kaspad/netadapter/netconnection.go
Svarog 6a18b56587
[NOD-1162] Fixes from integration test (#821)
* [NOD-1162] [FIX] Connection manager should run the moment it adds a request

* [NOD-1162] [FIX] Set peerID on handshake

* [NOD-1162] [FIX] Broadcast should send to outgoing route, not incoming

* [NOD-1162] [FIX] Add CmdInvRelayBlock to MakeEmptyMessage

* [NOD-1162] [FIX] Initialize Hash before decoding MsgInvRelayBlock

* [NOD-1162] [FIX] Invert condition

* [NOD-1162] [FIX] Fixes to encoding of MsgGetRelayBlocks

* [NOD-1162] [FIX] Add MsgGetRelayBlocks to MakeEmptyMessage

* [NOD-1162] Add comment
2020-07-26 11:44:16 +03:00

51 lines
1.3 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) *NetConnection {
return &NetConnection{
connection: connection,
}
}
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
}
// SetID sets the ID associated with this connection
func (c *NetConnection) SetID(peerID *id.ID) {
c.id = peerID
}
// Address returns the address associated with this connection
func (c *NetConnection) Address() string {
return c.connection.Address().String()
}
// IsOutbound returns whether the connection is outbound
func (c *NetConnection) IsOutbound() bool {
return c.connection.IsOutbound()
}
// SetOnInvalidMessageHandler sets a handler function
// for invalid messages
func (c *NetConnection) SetOnInvalidMessageHandler(onInvalidMessageHandler server.OnInvalidMessageHandler) {
c.connection.SetOnInvalidMessageHandler(onInvalidMessageHandler)
}