@@ -11,16 +11,18 @@ import (
1111 "github.com/faws-vcs/faws/faws/app"
1212 "github.com/faws-vcs/faws/faws/repo/cas"
1313 "github.com/faws-vcs/faws/faws/repo/event"
14+ "github.com/faws-vcs/faws/faws/repo/p2p/peernet"
1415)
1516
1617var (
1718 stages_text = map [event.Stage ]string {
18- event .StagePullObjects : "Retrieve objects" ,
19- event .StagePullTags : "Retrieve tags" ,
20- event .StageCacheFiles : "Cache files" ,
21- event .StageCacheFile : "Cache file" ,
22- event .StageWriteTree : "Write tree" ,
23- event .StageCheckout : "Checkout" ,
19+ event .StagePullObjects : "Retrieve objects" ,
20+ event .StagePullTags : "Retrieve tags" ,
21+ event .StageCacheFiles : "Cache files" ,
22+ event .StageCacheFile : "Cache file" ,
23+ event .StageWriteTree : "Write tree" ,
24+ event .StageCheckout : "Checkout" ,
25+ event .StageServeObjects : "Distribute objects" ,
2426 }
2527
2628 scrn activity_screen
@@ -54,6 +56,12 @@ type activity_screen struct {
5456
5557 connected_peers int
5658
59+ received_messages int64
60+ last_message_id peernet.MessageID
61+ object_uploads int64
62+ duplicate_object_downloads int64
63+ duplicate_object_download_size uint64
64+
5765 verbose bool
5866}
5967
@@ -166,6 +174,14 @@ func notify(ev event.Notification, params *event.NotifyParams) {
166174 case event .NotifyPeerDisconnected :
167175 // app.Info("disconnected from", params.ID)
168176 scrn .connected_peers --
177+ case event .NotifyPeerNetMessage :
178+ scrn .received_messages ++
179+ scrn .last_message_id = params .MessageID
180+ case event .NotifyPeerObjectUpload :
181+ scrn .object_uploads ++
182+ case event .NotifyPeerObjectDuplicateDownload :
183+ scrn .duplicate_object_downloads ++
184+ scrn .duplicate_object_download_size += uint64 (params .Count )
169185 }
170186 guard .Unlock ()
171187
@@ -230,6 +246,21 @@ func render_activity_screen(hud *console.Hud) {
230246 return
231247 }
232248
249+ // if scrn.received_messages > 0 {
250+ // var received_messages_text console.Text
251+ // received_messages_text.Stylesheet.Width = console.Width()
252+ // received_messages_text.Add(fmt.Sprintf("%d messages received. last message id: %s", scrn.received_messages, scrn.last_message_id), 0, 0)
253+ // hud.Line(&received_messages_text)
254+ // }
255+
256+ if scrn .connected_peers > 0 {
257+ var peers_text console.Text
258+ peers_text .Stylesheet .Margin [console .Left ] = 1
259+ peers_text .Stylesheet .Width = console .Width ()
260+ peers_text .Add (fmt .Sprintf ("%d peers connected" , scrn .connected_peers ), 0 , 0 )
261+ hud .Line (& peers_text )
262+ }
263+
233264 var progress_bar console.ProgressBar
234265 progress_bar .Stylesheet .Sequence [console .PbCaseLeft ] = console.Cell {'[' , 0 , 0 }
235266 progress_bar .Stylesheet .Sequence [console .PbCaseRight ] = console.Cell {']' , 0 , 0 }
@@ -249,18 +280,23 @@ func render_activity_screen(hud *console.Hud) {
249280 progress_bar .Progress = float64 (scrn .tags_received ) / float64 (scrn .tags_in_queue )
250281 hud .Line (& progress_bar )
251282 case event .StagePullObjects :
252- if scrn .connected_peers > 0 {
253- var peers_text console.Text
254- peers_text .Stylesheet .Margin [console .Left ] = 1
255- peers_text .Stylesheet .Width = console .Width ()
256- peers_text .Add (fmt .Sprintf ("%d peers connected" , scrn .connected_peers ), 0 , 0 )
257- hud .Line (& peers_text )
283+
284+ if scrn .duplicate_object_downloads > 0 {
285+ var duplicate_objects_text console.Text
286+ duplicate_objects_text .Stylesheet .Margin [console .Left ] = 1
287+ duplicate_objects_text .Stylesheet .Width = console .Width ()
288+ duplicate_objects_text .Add (
289+ fmt .Sprintf ("%d duplicate objects downloaded (%s wasted)" , scrn .duplicate_object_downloads , humanize .Bytes (scrn .duplicate_object_download_size )),
290+ console .BrightYellow ,
291+ 0 ,
292+ )
293+ hud .Line (& duplicate_objects_text )
258294 }
259295
260296 var usage_text console.Text
261297 usage_text .Stylesheet .Width = console .Width ()
262298 usage_text .Stylesheet .Margin [console .Left ] = 1
263- usage_text .Add (fmt .Sprintf ("%d/%d objects received , %s total" , scrn .objects_received , scrn .objects_in_queue , humanize .Bytes (scrn .bytes_received )), 0 , 0 )
299+ usage_text .Add (fmt .Sprintf ("%d/%d objects processed , %s total" , scrn .objects_received , scrn .objects_in_queue , humanize .Bytes (scrn .bytes_received )), 0 , 0 )
264300 hud .Line (& usage_text )
265301
266302 // if scrn.objects_received > 0 {
@@ -305,5 +341,10 @@ func render_activity_screen(hud *console.Hud) {
305341
306342 hud .Line (& file_name_text )
307343 hud .Line (& progress_text , & progress_bar )
344+ case event .StageServeObjects :
345+ var object_upload_count_text console.Text
346+ object_upload_count_text .Stylesheet .Width = console .Width ()
347+ object_upload_count_text .Add (fmt .Sprintf ("%d objects uploaded" , scrn .object_uploads ), 0 , 0 )
348+ hud .Line (& object_upload_count_text )
308349 }
309350}
0 commit comments