server: Reject outbound conns to non-full nodes.
This modifies the server connection code to reject outbound peers that do not offer full node services.
This commit is contained in:
parent
7b103e2434
commit
9151ebc90b
1 changed files with 18 additions and 0 deletions
18
server.go
18
server.go
|
@ -385,6 +385,12 @@ func (sp *serverPeer) addBanScore(persistent, transient uint32, reason string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasServices returns whether or not the provided advertised service flags have
|
||||||
|
// all of the provided desired service flags set.
|
||||||
|
func hasServices(advertised, desired wire.ServiceFlag) bool {
|
||||||
|
return advertised&desired == desired
|
||||||
|
}
|
||||||
|
|
||||||
// OnVersion is invoked when a peer receives a version bitcoin message
|
// OnVersion is invoked when a peer receives a version bitcoin message
|
||||||
// and is used to negotiate the protocol version details as well as kick start
|
// and is used to negotiate the protocol version details as well as kick start
|
||||||
// the communications.
|
// the communications.
|
||||||
|
@ -395,6 +401,18 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) *wire.MsgRej
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reject outbound peers that are not full nodes.
|
||||||
|
wantServices := wire.SFNodeNetwork
|
||||||
|
if !sp.Inbound() && !hasServices(msg.Services, wantServices) {
|
||||||
|
missingServices := wantServices & ^msg.Services
|
||||||
|
srvrLog.Debugf("Rejecting peer %s with services %v due to not "+
|
||||||
|
"providing desired services %v", sp.Peer, msg.Services,
|
||||||
|
missingServices)
|
||||||
|
reason := fmt.Sprintf("required services %#x not offered",
|
||||||
|
uint64(missingServices))
|
||||||
|
return wire.NewMsgReject(msg.Command(), wire.RejectNonstandard, reason)
|
||||||
|
}
|
||||||
|
|
||||||
// Add the remote peer time as a sample for creating an offset against
|
// Add the remote peer time as a sample for creating an offset against
|
||||||
// the local clock to keep the network time in sync.
|
// the local clock to keep the network time in sync.
|
||||||
sp.server.timeSource.AddTimeSample(sp.Addr(), msg.Timestamp)
|
sp.server.timeSource.AddTimeSample(sp.Addr(), msg.Timestamp)
|
||||||
|
|
Loading…
Reference in a new issue