mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
peer: Add support for specifying ua comments.
This adds a new parameter named UserAgentComments to the peer Config struct so that callers may specify additional comments to add to the user agent string. It also updates the server to include the prelease portion of the semantic version as a comment when creating peers.
This commit is contained in:
parent
36f61d8ebd
commit
97a8f5f34c
@ -227,6 +227,12 @@ type Config struct {
|
||||
// form "major.minor.revision" e.g. "2.6.41".
|
||||
UserAgentVersion string
|
||||
|
||||
// UserAgentComments specifies any additional comments to include the in
|
||||
// user agent to advertise. This is optional, so it may be nil. If
|
||||
// specified, the comments should only exist of characters from the
|
||||
// semantic alphabet [a-zA-Z0-9-].
|
||||
UserAgentComments []string
|
||||
|
||||
// ChainParams identifies which chain parameters the peer is associated
|
||||
// with. It is highly recommended to specify this field, however it can
|
||||
// be omitted in which case the test network will be used.
|
||||
@ -1869,7 +1875,8 @@ func (p *Peer) localVersionMsg() (*wire.MsgVersion, error) {
|
||||
|
||||
// Version message.
|
||||
msg := wire.NewMsgVersion(ourNA, theirNA, nonce, int32(blockNum))
|
||||
msg.AddUserAgent(p.cfg.UserAgentName, p.cfg.UserAgentVersion)
|
||||
msg.AddUserAgent(p.cfg.UserAgentName, p.cfg.UserAgentVersion,
|
||||
p.cfg.UserAgentComments...)
|
||||
|
||||
// Advertise local services.
|
||||
msg.Services = p.cfg.Services
|
||||
|
||||
24
server.go
24
server.go
@ -1583,6 +1583,11 @@ func disconnectPeer(peerList map[int32]*serverPeer, compareFunc func(*serverPeer
|
||||
|
||||
// newPeerConfig returns the configuration for the given serverPeer.
|
||||
func newPeerConfig(sp *serverPeer) *peer.Config {
|
||||
var userAgentComments []string
|
||||
if appPreRelease != "" {
|
||||
userAgentComments = append(userAgentComments, appPreRelease)
|
||||
}
|
||||
|
||||
return &peer.Config{
|
||||
Listeners: peer.MessageListeners{
|
||||
OnVersion: sp.OnVersion,
|
||||
@ -1604,15 +1609,16 @@ func newPeerConfig(sp *serverPeer) *peer.Config {
|
||||
OnRead: sp.OnRead,
|
||||
OnWrite: sp.OnWrite,
|
||||
},
|
||||
NewestBlock: sp.newestBlock,
|
||||
HostToNetAddress: sp.server.addrManager.HostToNetAddress,
|
||||
Proxy: cfg.Proxy,
|
||||
UserAgentName: userAgentName,
|
||||
UserAgentVersion: userAgentVersion,
|
||||
ChainParams: sp.server.chainParams,
|
||||
Services: sp.server.services,
|
||||
DisableRelayTx: cfg.BlocksOnly,
|
||||
ProtocolVersion: maxProtocolVersion,
|
||||
NewestBlock: sp.newestBlock,
|
||||
HostToNetAddress: sp.server.addrManager.HostToNetAddress,
|
||||
Proxy: cfg.Proxy,
|
||||
UserAgentName: userAgentName,
|
||||
UserAgentVersion: userAgentVersion,
|
||||
UserAgentComments: userAgentComments,
|
||||
ChainParams: sp.server.chainParams,
|
||||
Services: sp.server.services,
|
||||
DisableRelayTx: cfg.BlocksOnly,
|
||||
ProtocolVersion: maxProtocolVersion,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user