Change msgNewSequence function to use parameters

This commit is contained in:
Kleissner
2021-10-17 17:53:48 +02:00
parent 1b93eac17a
commit 42ff6d926e
2 changed files with 6 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ import (
// pingConnection sends a ping to the target peer via the specified connection
func (peer *PeerInfo) pingConnection(connection *Connection) {
raw := &protocol.PacketRaw{Command: protocol.CommandPing, Sequence: peer.msgNewSequence(nil).sequence}
raw := &protocol.PacketRaw{Command: protocol.CommandPing, Sequence: msgNewSequence(peer.PublicKey, &peer.messageSequence, nil).sequence}
Filters.MessageOutPing(peer, raw, connection)
err := peer.sendConnection(raw, connection)
@@ -37,7 +37,7 @@ func (peer *PeerInfo) sendAnnouncement(sendUA, findSelf bool, findPeer []KeyHash
packets = msgEncodeAnnouncement(sendUA, findSelf, findPeer, findValue, files, FeatureSupport(), blockchainHeight, blockchainVersion)
for _, packet := range packets {
packet.sequence = peer.msgNewSequence(sequenceData)
packet.sequence = msgNewSequence(peer.PublicKey, &peer.messageSequence, sequenceData)
raw := &protocol.PacketRaw{Command: protocol.CommandAnnouncement, Payload: packet.raw, Sequence: packet.sequence.sequence}
Filters.MessageOutAnnouncement(peer.PublicKey, peer, raw, findSelf, findPeer, findValue, files)
packet.err = peer.send(raw)

View File

@@ -58,18 +58,18 @@ func initMessageSequence() {
}()
}
// msgNewSequence returns a new sequence and registers is
// msgNewSequence returns a new sequence and registers it. messageSequence must point to the variable holding the continuous next sequence number.
// Use only for Announcement and Ping messages.
func (peer *PeerInfo) msgNewSequence(data interface{}) (info *sequenceExpiry) {
func msgNewSequence(publicKey *btcec.PublicKey, messageSequence *uint32, data interface{}) (info *sequenceExpiry) {
info = &sequenceExpiry{
sequence: atomic.AddUint32(&peer.messageSequence, 1),
sequence: atomic.AddUint32(messageSequence, 1),
created: time.Now(),
expires: time.Now().Add(time.Duration(ReplyTimeout) * time.Second),
data: data,
}
// Add the sequence to the list. Sequences are unique enough that collisions are unlikely and negligible.
key := string(peer.PublicKey.SerializeCompressed()) + strconv.FormatUint(uint64(info.sequence), 10)
key := string(publicKey.SerializeCompressed()) + strconv.FormatUint(uint64(info.sequence), 10)
sequencesMutex.Lock()
sequences[key] = info
sequencesMutex.Unlock()