remove gossip method, start ad handling for node
This commit is contained in:
41
pkg/ad/ad.go
41
pkg/ad/ad.go
@@ -2,10 +2,7 @@ package ad
|
||||
|
||||
import (
|
||||
"github.com/indra-labs/indra/pkg/engine/coding"
|
||||
"github.com/indra-labs/indra/pkg/engine/sess"
|
||||
log2 "github.com/indra-labs/indra/pkg/proc/log"
|
||||
"github.com/indra-labs/indra/pkg/util/cryptorand"
|
||||
"github.com/indra-labs/indra/pkg/util/qu"
|
||||
"github.com/indra-labs/indra/pkg/util/splice"
|
||||
)
|
||||
|
||||
@@ -20,42 +17,4 @@ type Ad interface {
|
||||
coding.Codec
|
||||
Splice(s *splice.Splice)
|
||||
Validate() bool
|
||||
Gossip(sm *sess.Manager, c qu.C)
|
||||
}
|
||||
|
||||
// Gossip writes a new Ad out to the p2p network.
|
||||
//
|
||||
// todo: this will be changed to use the engine host peer store. An interface
|
||||
//
|
||||
// will be required.
|
||||
func Gossip(x Ad, sm *sess.Manager, c qu.C) {
|
||||
done := qu.T()
|
||||
msg := splice.New(x.Len())
|
||||
if fails(x.Encode(msg)) {
|
||||
return
|
||||
}
|
||||
nPeers := sm.NodesLen()
|
||||
peerIndices := make([]int, nPeers)
|
||||
for i := 1; i < nPeers; i++ {
|
||||
peerIndices[i] = i
|
||||
}
|
||||
cryptorand.Shuffle(nPeers, func(i, j int) {
|
||||
peerIndices[i], peerIndices[j] = peerIndices[j], peerIndices[i]
|
||||
})
|
||||
var cursor int
|
||||
for {
|
||||
select {
|
||||
case <-c.Wait():
|
||||
return
|
||||
case <-done:
|
||||
return
|
||||
default:
|
||||
}
|
||||
n := sm.FindNodeByIndex(peerIndices[cursor])
|
||||
n.Transport.Send(msg.GetAll())
|
||||
cursor++
|
||||
if cursor > len(peerIndices)-1 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user