kaspad/netadapter/netconnection.go
stasatdaglabs 8fdb5aa024
[NOD-1123] Implement banning (#812)
* [NOD-1123] Bubble bad-message errors up to the protocol level.

* [NOD-1123] Implement Banning.

* [NOD-1123] Properly use &stopped.

* [NOD-1123] Ban by IP rather than IP and port.

* [NOD-1123] Don't initiate connections to banned peers.

* [NOD-1123] Fix infinite loop in checkOutgoingConnections.

* [NOD-1123] Fix bannedAddresses key.

* [NOD-1123] Rename onBadMessageHandler to onInvalidMessageHandler.
2020-07-23 10:47:28 +03:00

42 lines
1.0 KiB
Go

package netadapter
import (
"fmt"
"github.com/kaspanet/kaspad/netadapter/id"
"github.com/kaspanet/kaspad/netadapter/server"
)
// NetConnection is a wrapper to a server connection for use by services external to NetAdapter
type NetConnection struct {
connection server.Connection
id *id.ID
}
func newNetConnection(connection server.Connection, id *id.ID) *NetConnection {
return &NetConnection{
connection: connection,
id: id,
}
}
func (c *NetConnection) String() string {
return fmt.Sprintf("<%s: %s>", c.id, c.connection)
}
// ID returns the ID associated with this connection
func (c *NetConnection) ID() *id.ID {
return c.id
}
// Address returns the address associated with this connection
func (c *NetConnection) Address() string {
return c.connection.Address().String()
}
// SetOnInvalidMessageHandler sets a handler function
// for invalid messages
func (c *NetConnection) SetOnInvalidMessageHandler(onInvalidMessageHandler server.OnInvalidMessageHandler) {
c.connection.SetOnInvalidMessageHandler(onInvalidMessageHandler)
}