Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: Minor function definition order cleanup. #1271

Merged
merged 1 commit into from
Jun 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 30 additions & 36 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,36 @@ func (sp *serverPeer) OnGetHeaders(p *peer.Peer, msg *wire.MsgGetHeaders) {
p.QueueMessage(&wire.MsgHeaders{Headers: blockHeaders}, nil)
}

// enforceNodeCFFlag disconnects the peer if the server is not configured to
// allow committed filters. Additionally, if the peer has negotiated to a
// protocol version that is high enough to observe the committed filter service
// support bit, it will be banned since it is intentionally violating the
// protocol.
func (sp *serverPeer) enforceNodeCFFlag(cmd string) bool {
if sp.server.services&wire.SFNodeCF != wire.SFNodeCF {
// Ban the peer if the protocol version is high enough that the peer is
// knowingly violating the protocol and banning is enabled.
//
// NOTE: Even though the addBanScore function already examines whether
// or not banning is enabled, it is checked here as well to ensure the
// violation is logged and the peer is disconnected regardless.
if sp.ProtocolVersion() >= wire.NodeCFVersion && !cfg.DisableBanning {
// Disonnect the peer regardless of whether it was banned.
sp.addBanScore(100, 0, cmd)
sp.Disconnect()
return false
}

// Disconnect the peer regardless of protocol version or banning state.
peerLog.Debugf("%s sent an unsupported %s request -- disconnecting", sp,
cmd)
sp.Disconnect()
return false
}

return true
}

// OnGetCFilter is invoked when a peer receives a getcfilter wire message.
func (sp *serverPeer) OnGetCFilter(p *peer.Peer, msg *wire.MsgGetCFilter) {
// Disconnect and/or ban depending on the node cf services flag and
Expand Down Expand Up @@ -1004,42 +1034,6 @@ func (sp *serverPeer) OnGetCFTypes(p *peer.Peer, msg *wire.MsgGetCFTypes) {
sp.QueueMessage(cfTypesMsg, nil)
}

// enforceNodeCFFlag disconnects the peer if the server is not configured to
// allow committed filters. Additionally, if the peer has negotiated to a
// protocol version that is high enough to observe the committed filter service
// support bit, it will be banned since it is intentionally violating the
// protocol.
func (sp *serverPeer) enforceNodeCFFlag(cmd string) bool {
if sp.server.services&wire.SFNodeCF != wire.SFNodeCF {
// Ban the peer if the protocol version is high enough that the
// peer is knowingly violating the protocol and banning is
// enabled.
//
// NOTE: Even though the addBanScore function already examines
// whether or not banning is enabled, it is checked here as well
// to ensure the violation is logged and the peer is
// disconnected regardless.
if sp.ProtocolVersion() >= wire.NodeCFVersion &&
!cfg.DisableBanning {

// Disonnect the peer regardless of whether it was
// banned.
sp.addBanScore(100, 0, cmd)
sp.Disconnect()
return false
}

// Disconnect the peer regardless of protocol version or banning
// state.
peerLog.Debugf("%s sent an unsupported %s request -- "+
"disconnecting", sp, cmd)
sp.Disconnect()
return false
}

return true
}

// OnGetAddr is invoked when a peer receives a getaddr wire message and is used
// to provide the peer with known addresses from the address manager.
func (sp *serverPeer) OnGetAddr(p *peer.Peer, msg *wire.MsgGetAddr) {
Expand Down