Skip to content

Commit

Permalink
improve relayer peer choice
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed May 22, 2024
1 parent 1826f40 commit 292bf7a
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions p2p/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,24 +448,17 @@ func (me *Peer) relayOrHandlePeerMessage(relayerId crypto.Hash, msg *PeerMessage
if me.relayer == nil {
return nil
}
data := append([]byte{PeerMessageTypeRelay}, msg.Data...)
peer := me.consumers.Get(to)
if peer == nil {
peer = me.relayers.Get(to)
}
if peer != nil {
rk := crypto.Blake3Hash(append(msg.Data, to[:]...))
rk = crypto.Blake3Hash(append(rk[:], relayerId[:]...))
success, _ := peer.offer(MsgPriorityNormal, &ChanMsg{rk[:], data})
if !success {
return fmt.Errorf("peer.offer(%s) consumer timeout", peer.IdForNetwork)
}
return nil
if peer == nil {
peer = me.remoteRelayers.Get(to)
}
peer = me.remoteRelayers.Get(to)
if peer == nil || peer.IdForNetwork == relayerId {
return nil
}
data := append([]byte{PeerMessageTypeRelay}, msg.Data...)
rk := crypto.Blake3Hash(append(msg.Data, to[:]...))
rk = crypto.Blake3Hash(append(rk[:], relayerId[:]...))
success, _ := peer.offer(MsgPriorityNormal, &ChanMsg{rk[:], data})
Expand Down

0 comments on commit 292bf7a

Please sign in to comment.