mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-16 18:37:51 +01:00
Rename field sequence in MessageRaw due to name collision in PacketRaw
This commit is contained in:
@@ -139,7 +139,7 @@ func (peer *PeerInfo) peer2Record(allowLocal, allowIPv4, allowIPv6 bool) (result
|
||||
// cmdResponse handles the response to the announcement
|
||||
func (peer *PeerInfo) cmdResponse(msg *MessageResponse, connection *Connection) {
|
||||
// The sequence data is used to correlate this response with the announcement.
|
||||
if msg.sequence == nil || msg.sequence.data == nil {
|
||||
if msg.SequenceInfo == nil || msg.SequenceInfo.Data == nil {
|
||||
// If there is no sequence data but there were results returned, it means we received unsolicited response data. It will be rejected.
|
||||
if len(msg.HashesNotFound) > 0 || len(msg.Hash2Peers) > 0 || len(msg.FilesEmbed) > 0 {
|
||||
Filters.LogError("cmdResponse", "unsolicited response data received from %s\n", connection.Address.String())
|
||||
@@ -149,7 +149,7 @@ func (peer *PeerInfo) cmdResponse(msg *MessageResponse, connection *Connection)
|
||||
}
|
||||
|
||||
// bootstrap FIND_SELF?
|
||||
if _, ok := msg.sequence.data.(*bootstrapFindSelf); ok {
|
||||
if _, ok := msg.SequenceInfo.Data.(*bootstrapFindSelf); ok {
|
||||
for _, hash2Peer := range msg.Hash2Peers {
|
||||
// Make sure no garbage is returned. The key must be self and only Closest is expected.
|
||||
if !bytes.Equal(hash2Peer.ID.Hash, nodeID) || len(hash2Peer.Closest) == 0 {
|
||||
@@ -164,10 +164,10 @@ func (peer *PeerInfo) cmdResponse(msg *MessageResponse, connection *Connection)
|
||||
}
|
||||
|
||||
// Response to an information request?
|
||||
if _, ok := msg.sequence.data.(*dht.InformationRequest); ok {
|
||||
if _, ok := msg.SequenceInfo.Data.(*dht.InformationRequest); ok {
|
||||
// Future: Once multiple information requests are pooled (multiplexed) into one or multiple Announcement sequences (messages), the responses need to be de-pooled.
|
||||
// A simple multiplex structure linked via the sequence containing a map (hash 2 IR) could simplify this.
|
||||
info := msg.sequence.data.(*dht.InformationRequest)
|
||||
info := msg.SequenceInfo.Data.(*dht.InformationRequest)
|
||||
|
||||
if len(msg.HashesNotFound) > 0 {
|
||||
info.Done()
|
||||
|
||||
@@ -49,7 +49,7 @@ const (
|
||||
type MessageRaw struct {
|
||||
protocol.PacketRaw
|
||||
SenderPublicKey *btcec.PublicKey // Sender Public Key, ECDSA (secp256k1) 257-bit
|
||||
sequence *sequenceExpiry // Sequence
|
||||
SequenceInfo *SequenceExpiry // Sequence
|
||||
}
|
||||
|
||||
// MessageAnnouncement is the decoded announcement message.
|
||||
|
||||
@@ -27,19 +27,20 @@ import (
|
||||
|
||||
// sequences stores all sequence numbers that are valid at the moment. The value represents the time the sequence number was used.
|
||||
// Key = Peer ID + Sequence Number
|
||||
var sequences map[string]*sequenceExpiry
|
||||
var sequences map[string]*SequenceExpiry
|
||||
var sequencesMutex sync.Mutex
|
||||
|
||||
type sequenceExpiry struct {
|
||||
// SequenceExpiry contains the decoded sequence information of a message.
|
||||
type SequenceExpiry struct {
|
||||
sequence uint32 // Sequence number
|
||||
created time.Time // When the sequence was created.
|
||||
expires time.Time // When the sequence expires. This can be extended on the fly!
|
||||
counter int // How many replies used the sequence. Multiple Response messages may be returned for a single Announcement one.
|
||||
data interface{} // Optional high-level data associated with the sequence
|
||||
Data interface{} // Optional high-level data associated with the sequence
|
||||
}
|
||||
|
||||
func initMessageSequence() {
|
||||
sequences = make(map[string]*sequenceExpiry)
|
||||
sequences = make(map[string]*SequenceExpiry)
|
||||
|
||||
// auto-delete worker to remove expired sequences
|
||||
go func() {
|
||||
@@ -60,12 +61,12 @@ func initMessageSequence() {
|
||||
|
||||
// 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 msgNewSequence(publicKey *btcec.PublicKey, messageSequence *uint32, data interface{}) (info *sequenceExpiry) {
|
||||
info = &sequenceExpiry{
|
||||
func msgNewSequence(publicKey *btcec.PublicKey, messageSequence *uint32, data interface{}) (info *SequenceExpiry) {
|
||||
info = &SequenceExpiry{
|
||||
sequence: atomic.AddUint32(messageSequence, 1),
|
||||
created: time.Now(),
|
||||
expires: time.Now().Add(time.Duration(ReplyTimeout) * time.Second),
|
||||
data: data,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
// Add the sequence to the list. Sequences are unique enough that collisions are unlikely and negligible.
|
||||
@@ -78,12 +79,12 @@ func msgNewSequence(publicKey *btcec.PublicKey, messageSequence *uint32, data in
|
||||
}
|
||||
|
||||
// msgArbitrarySequence returns an arbitrary sequence to be used for uncontacted peers
|
||||
func msgArbitrarySequence(publicKey *btcec.PublicKey, data interface{}) (info *sequenceExpiry) {
|
||||
info = &sequenceExpiry{
|
||||
func msgArbitrarySequence(publicKey *btcec.PublicKey, data interface{}) (info *SequenceExpiry) {
|
||||
info = &SequenceExpiry{
|
||||
sequence: rand.Uint32(),
|
||||
created: time.Now(),
|
||||
expires: time.Now().Add(time.Duration(ReplyTimeout) * time.Second),
|
||||
data: data,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
// Add the sequence to the list. Sequences are unique enough that collisions are unlikely and negligible.
|
||||
@@ -129,7 +130,7 @@ func msgValidateSequence(raw *MessageRaw, invalidate bool) (valid bool, rtt time
|
||||
sequence.expires = time.Now().Add(time.Duration(ReplyTimeout) * time.Second / 2)
|
||||
}
|
||||
|
||||
raw.sequence = sequence
|
||||
raw.SequenceInfo = sequence
|
||||
|
||||
return sequence.expires.After(time.Now()), rtt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user