SendTo() sends a message to a specific peer based on their public key
(publicKey []byte, topic lib.Topic, msg proto.Message)
| 234 | |
| 235 | // SendTo() sends a message to a specific peer based on their public key |
| 236 | func (ps *PeerSet) SendTo(publicKey []byte, topic lib.Topic, msg proto.Message) lib.ErrorI { |
| 237 | defer lib.TimeTrack(ps.logger, time.Now(), time.Second) |
| 238 | bz, err := lib.Marshal(msg) |
| 239 | if err != nil { |
| 240 | return err |
| 241 | } |
| 242 | unlock := rlockWithTrace("peerset", &ps.mux, ps.logger) |
| 243 | defer unlock() |
| 244 | peer, err := ps.get(publicKey) |
| 245 | if err != nil { |
| 246 | return err |
| 247 | } |
| 248 | return ps.send(peer, topic, bz) |
| 249 | } |
| 250 | |
| 251 | // SendToPeers() sends a message to all peers |
| 252 | func (ps *PeerSet) SendToPeers(topic lib.Topic, msg proto.Message, excludeKeys ...string) lib.ErrorI { |