MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / BroadcastEnvelope

Method BroadcastEnvelope

p2p/switch.go:272–294  ·  view source on GitHub ↗

--------------------------------------------------------------------- Peers BroadcastEnvelope runs a go routine for each attempted send, which will block trying to send for defaultSendTimeoutSeconds. Returns a channel which receives success values for each attempted send (false if times out). Channe

(e Envelope)

Source from the content-addressed store, hash-verified

270//
271// NOTE: BroadcastEnvelope uses goroutines, so order of broadcast may not be preserved.
272func (sw *Switch) BroadcastEnvelope(e Envelope) chan bool {
273 sw.Logger.Debug("Broadcast", "channel", e.ChannelID)
274
275 peers := sw.peers.List()
276 var wg sync.WaitGroup
277 wg.Add(len(peers))
278 successChan := make(chan bool, len(peers))
279
280 for _, peer := range peers {
281 go func(p Peer) {
282 defer wg.Done()
283 success := SendEnvelopeShim(p, e, sw.Logger)
284 successChan <- success
285 }(peer)
286 }
287
288 go func() {
289 wg.Wait()
290 close(successChan)
291 }()
292
293 return successChan
294}
295
296// Broadcast runs a go routine for each attempted send, which will block trying
297// to send for defaultSendTimeoutSeconds. Returns a channel which receives

Callers 12

SyncMethod · 0.80
TestSwitchesFunction · 0.80
BenchmarkSwitchBroadcastFunction · 0.80
sendStatusRequestMethod · 0.80

Calls 6

SendEnvelopeShimFunction · 0.85
DebugMethod · 0.65
ListMethod · 0.65
DoneMethod · 0.65
WaitMethod · 0.65
AddMethod · 0.45

Tested by 2

TestSwitchesFunction · 0.64
BenchmarkSwitchBroadcastFunction · 0.64