mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-19 20:46:45 +00:00

* [NOD-1124] Move Router to the router package. * [NOD-1124] Implement SetOnRouteCapacityReachedHandler. * [NOD-1124] Use Routes instead of bare channels. * [NOD-1124] Fix merge errors. * [NOD-1124] Connect the Router to the Connection. * [NOD-1124] Fix merge errors. * [NOD-1124] Move some variables around. * [NOD-1124] Fix unreachable code. * [NOD-1124] Fix a variable name. * [NOD-1124] Rename AddRoute to AddIncomingRoute. * [NOD-1124] Rename SetRouter to Start. * [NOD-1124] Make AddIncomingRoute create a Route by itself. * [NOD-1124] Replace IncomingRoute with EnqueueIncomingMessage. * [NOD-1124] Make Enqueue and Dequeue return isOpen instead of err. * [NOD-1124] Remove writeDuringDisconnectLock. * [NOD-1124] In sendLoop, move outgoingRoute to outside the loop. * [NOD-1124] Start the connection loops only when Start is called. * [NOD-1124] Replace OnIDReceivedHandler with AssociateRouterID. * [NOD-1124] Add isOpen to Enqueue and Dequeue. * [NOD-1124] Protect errChan from writing during disconnect.
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kaspanet/kaspad/netadapter/router"
|
|
"net"
|
|
)
|
|
|
|
// OnConnectedHandler is a function that is to be called
|
|
// once a new Connection is successfully established.
|
|
type OnConnectedHandler func(connection Connection) error
|
|
|
|
// OnDisconnectedHandler is a function that is to be
|
|
// called once a Connection has been disconnected.
|
|
type OnDisconnectedHandler func() error
|
|
|
|
// Server represents a p2p server.
|
|
type Server interface {
|
|
Connect(address string) (Connection, error)
|
|
Connections() []Connection
|
|
Start() error
|
|
Stop() error
|
|
SetOnConnectedHandler(onConnectedHandler OnConnectedHandler)
|
|
// TODO(libp2p): Move AddConnection and RemoveConnection to connection manager
|
|
AddConnection(connection Connection) error
|
|
RemoveConnection(connection Connection) error
|
|
}
|
|
|
|
// Connection represents a p2p server connection.
|
|
type Connection interface {
|
|
fmt.Stringer
|
|
Start(router *router.Router)
|
|
Disconnect() error
|
|
IsConnected() bool
|
|
SetOnDisconnectedHandler(onDisconnectedHandler OnDisconnectedHandler)
|
|
Address() net.Addr
|
|
}
|