mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
Change msgNewSequence function to use parameters
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user