forked from TrueCloudLab/neoneo-go
network: micro-optimize relayInventory
Do less allocations, we're sending the same message with the same payload.
This commit is contained in:
parent
9eb880a095
commit
0420d48e56
1 changed files with 5 additions and 14 deletions
|
@ -676,12 +676,14 @@ func (s *Server) requestTx(hashes ...util.Uint256) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) relayInventory(t payload.InventoryType, hashes ...util.Uint256) {
|
func (s *Server) relayInventory(t payload.InventoryType, hashes ...util.Uint256) {
|
||||||
|
payload := payload.NewInventory(t, hashes)
|
||||||
|
msg := NewMessage(s.Net, CMDInv, payload)
|
||||||
|
|
||||||
for peer := range s.Peers() {
|
for peer := range s.Peers() {
|
||||||
if !peer.Handshaked() {
|
if !peer.Handshaked() || !peer.Version().Relay {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
payload := payload.NewInventory(t, hashes)
|
peer.WriteMsg(msg)
|
||||||
s.RelayDirectly(peer, payload)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,14 +715,3 @@ func (s *Server) RelayTxn(t *transaction.Transaction) RelayReason {
|
||||||
|
|
||||||
return RelaySucceed
|
return RelaySucceed
|
||||||
}
|
}
|
||||||
|
|
||||||
// RelayDirectly relays directly the inventory to the remote peers.
|
|
||||||
// Reference: the method OnRelayDirectly in C#: https://github.com/neo-project/neo/blob/master/neo/Network/P2P/LocalNode.cs#L166
|
|
||||||
func (s *Server) RelayDirectly(p Peer, inv *payload.Inventory) {
|
|
||||||
if !p.Version().Relay {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
p.WriteMsg(NewMessage(s.Net, CMDInv, inv))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue