本文整理匯總了Golang中github.com/degdb/degdb/protocol.Message.SentTo方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.SentTo方法的具體用法?Golang Message.SentTo怎麽用?Golang Message.SentTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/degdb/degdb/protocol.Message
的用法示例。
在下文中一共展示了Message.SentTo方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Broadcast
// Broadcast sends a message to all peers with that have the hash in their keyspace.
func (s *Server) Broadcast(hash *uint64, msg *protocol.Message) error {
alreadySentTo := make(map[uint64]bool)
if msg.Gossip {
for _, to := range msg.SentTo {
alreadySentTo[to] = true
}
}
sentTo := []uint64{murmur3.Sum64([]byte(s.LocalPeer().Id))}
var toPeers []*Conn
for _, peer := range s.Peers {
peerHash := murmur3.Sum64([]byte(peer.Peer.Id))
if (hash == nil || peer.Peer.GetKeyspace().Includes(*hash)) && !alreadySentTo[peerHash] {
sentTo = append(sentTo, peerHash)
toPeers = append(toPeers, peer)
}
}
if msg.Gossip {
msg.SentTo = append(msg.SentTo, sentTo...)
}
for _, peer := range toPeers {
s.Printf("Broadcasting to %s", peer.Peer.Id)
if err := peer.Send(msg); err != nil {
return err
}
}
return nil
}