mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00

* [NOD-1579] Remove selected tip hash messages. * [NOD-1579] Start moving IBD stuff into blockrelay. * [NOD-1579] Rename relaytransactions to transactionrelay. * [NOD-1579] Move IBD files into blockrelay. * [NOD-1579] Remove flow stuff from ibd.go. * [NOD-1579] Bring back IsInIBD(). * [NOD-1579] Simplify block relay flow. * [NOD-1579] Check orphan pool for missing parents to avoid unnecessary processing. * [NOD-1579] Implement processOrphan. * [NOD-1579] Implement addToOrphanSetAndRequestMissingParents. * [NOD-1579] Fix TestIBD. * [NOD-1579] Implement isBlockInOrphanResolutionRange. * [NOD-1579] Implement limited block locators. * [NOD-1579] Add some comments. * [NOD-1579] Specifically check for StatusHeaderOnly in blockrelay. * [NOD-1579] Simplify runIBDIfNotRunning. * [NOD-1579] Don't run IBD if it is already running. * [NOD-1579] Fix a comment. * [NOD-1579] Rename mode to syncInfo. * [NOD-1579] Simplify validateAndInsertBlock. * [NOD-1579] Fix bad SyncStateSynced condition. * [NOD-1579] Implement validateAgainstSyncStateAndResolveInsertMode. * [NOD-1579] Use insertModeHeader. * [NOD-1579] Add logs to TrySetIBDRunning and UnsetIBDRunning. * [NOD-1579] Implement and use dequeueIncomingMessageAndSkipInvs. * [NOD-1579] Fix a log. * [NOD-1579] Fix a bug in createBlockLocator. * [NOD-1579] Rename a variable. * [NOD-1579] Fix a slew of bugs in missingBlockBodyHashes and selectedChildIterator. * [NOD-1579] Fix bad chunk size in syncMissingBlockBodies. * [NOD-1579] Remove maxOrphanBlueScoreDiff. * [NOD-1579] Fix merge errors. * [NOD-1579] Remove a debug log. * [NOD-1579] Add logs. * [NOD-1579] Make various go quality tools happy. * [NOD-1579] Fix a typo in a variable name. * [NOD-1579] Fix full blocks over header-only blocks not failing the missing-parents validation. * [NOD-1579] Add an error log about a condition that should never happen. * [NOD-1579] Check all antiPast hashes instead of just the lowHash's anticone to filter for header-only blocks. * [NOD-1579] Remove the nil stuff from GetBlockLocator. * [NOD-1579] Remove superfluous condition in handleRelayInvsFlow.start(). * [NOD-1579] Return a boolean from requestBlock instead of comparing to nil. * [NOD-1579] Fix a bad log.Debugf. * [NOD-1579] Remove a redundant check. * [NOD-1579] Change an info log to a warning log. * [NOD-1579] Move OnNewBlock out of relayBlock. * [NOD-1579] Remove redundant exists check from runIBDIfNotRunning. * [NOD-1579] Fix bad call to OnNewBlock. * [NOD-1579] Remove an impossible check. * [NOD-1579] Added a log. * [NOD-1579] Rename insertModeBlockWithoutUpdatingVirtual to insertModeBlockBody. * [NOD-1579] Add a check for duplicate headers. * [NOD-1579] Added a comment. * [NOD-1579] Tighten a stop condition. * [NOD-1579] Simplify a log. * [NOD-1579] Clarify a log. * [NOD-1579] Move a log.
126 lines
4.0 KiB
Go
126 lines
4.0 KiB
Go
// Copyright (c) 2013-2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package appmessage
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
"github.com/kaspanet/kaspad/version"
|
|
|
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/id"
|
|
"github.com/kaspanet/kaspad/util/mstime"
|
|
)
|
|
|
|
// MaxUserAgentLen is the maximum allowed length for the user agent field in a
|
|
// version message (MsgVersion).
|
|
const MaxUserAgentLen = 256
|
|
|
|
// DefaultUserAgent for appmessage in the stack
|
|
var DefaultUserAgent = fmt.Sprintf("/kaspad:%s/", version.Version())
|
|
|
|
// MsgVersion implements the Message interface and represents a kaspa version
|
|
// message. It is used for a peer to advertise itself as soon as an outbound
|
|
// connection is made. The remote peer then uses this information along with
|
|
// its own to negotiate. The remote peer must then respond with a version
|
|
// message of its own containing the negotiated values followed by a verack
|
|
// message (MsgVerAck). This exchange must take place before any further
|
|
// communication is allowed to proceed.
|
|
type MsgVersion struct {
|
|
baseMessage
|
|
// Version of the protocol the node is using.
|
|
ProtocolVersion uint32
|
|
|
|
// The peer's network (mainnet, testnet, etc.)
|
|
Network string
|
|
|
|
// Bitfield which identifies the enabled services.
|
|
Services ServiceFlag
|
|
|
|
// Time the message was generated. This is encoded as an int64 on the appmessage.
|
|
Timestamp mstime.Time
|
|
|
|
// Address of the local peer.
|
|
Address *NetAddress
|
|
|
|
// The peer unique ID
|
|
ID *id.ID
|
|
|
|
// The user agent that generated messsage. This is a encoded as a varString
|
|
// on the appmessage. This has a max length of MaxUserAgentLen.
|
|
UserAgent string
|
|
|
|
// Don't announce transactions to peer.
|
|
DisableRelayTx bool
|
|
|
|
// The subnetwork of the generator of the version message. Should be nil in full nodes
|
|
SubnetworkID *externalapi.DomainSubnetworkID
|
|
}
|
|
|
|
// HasService returns whether the specified service is supported by the peer
|
|
// that generated the message.
|
|
func (msg *MsgVersion) HasService(service ServiceFlag) bool {
|
|
return msg.Services&service == service
|
|
}
|
|
|
|
// AddService adds service as a supported service by the peer generating the
|
|
// message.
|
|
func (msg *MsgVersion) AddService(service ServiceFlag) {
|
|
msg.Services |= service
|
|
}
|
|
|
|
// Command returns the protocol command string for the message. This is part
|
|
// of the Message interface implementation.
|
|
func (msg *MsgVersion) Command() MessageCommand {
|
|
return CmdVersion
|
|
}
|
|
|
|
// NewMsgVersion returns a new kaspa version message that conforms to the
|
|
// Message interface using the passed parameters and defaults for the remaining
|
|
// fields.
|
|
func NewMsgVersion(addr *NetAddress, id *id.ID, network string,
|
|
subnetworkID *externalapi.DomainSubnetworkID) *MsgVersion {
|
|
|
|
// Limit the timestamp to one millisecond precision since the protocol
|
|
// doesn't support better.
|
|
return &MsgVersion{
|
|
ProtocolVersion: ProtocolVersion,
|
|
Network: network,
|
|
Services: 0,
|
|
Timestamp: mstime.Now(),
|
|
Address: addr,
|
|
ID: id,
|
|
UserAgent: DefaultUserAgent,
|
|
DisableRelayTx: false,
|
|
SubnetworkID: subnetworkID,
|
|
}
|
|
}
|
|
|
|
// ValidateUserAgent checks userAgent length against MaxUserAgentLen
|
|
func ValidateUserAgent(userAgent string) error {
|
|
if len(userAgent) > MaxUserAgentLen {
|
|
str := fmt.Sprintf("user agent too long [len %d, max %d]",
|
|
len(userAgent), MaxUserAgentLen)
|
|
return messageError("MsgVersion", str)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// AddUserAgent adds a user agent to the user agent string for the version
|
|
// message. The version string is not defined to any strict format, although
|
|
// it is recommended to use the form "major.minor.revision" e.g. "2.6.41".
|
|
func (msg *MsgVersion) AddUserAgent(name string, version string,
|
|
comments ...string) {
|
|
|
|
newUserAgent := fmt.Sprintf("%s:%s", name, version)
|
|
if len(comments) != 0 {
|
|
newUserAgent = fmt.Sprintf("%s(%s)", newUserAgent,
|
|
strings.Join(comments, "; "))
|
|
}
|
|
newUserAgent = fmt.Sprintf("%s%s/", msg.UserAgent, newUserAgent)
|
|
msg.UserAgent = newUserAgent
|
|
}
|