mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-08 15:16:41 +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.
39 lines
863 B
Go
39 lines
863 B
Go
package grpcserver
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/netadapter/server/grpcserver/protowire"
|
|
"github.com/kaspanet/kaspad/util/panics"
|
|
"github.com/pkg/errors"
|
|
"google.golang.org/grpc/peer"
|
|
)
|
|
|
|
type p2pServer struct {
|
|
protowire.UnimplementedP2PServer
|
|
server *gRPCServer
|
|
}
|
|
|
|
func newP2PServer(s *gRPCServer) *p2pServer {
|
|
return &p2pServer{server: s}
|
|
}
|
|
|
|
func (p *p2pServer) MessageStream(stream protowire.P2P_MessageStreamServer) error {
|
|
defer panics.HandlePanic(log, nil)
|
|
|
|
peerInfo, ok := peer.FromContext(stream.Context())
|
|
if !ok {
|
|
return errors.Errorf("Error getting stream peer info from context")
|
|
}
|
|
connection := newConnection(p.server, peerInfo.Addr, false, stream)
|
|
|
|
err := p.server.onConnectedHandler(connection)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Infof("Incoming connection from %s", peerInfo.Addr)
|
|
|
|
<-connection.stopChan
|
|
|
|
return nil
|
|
}
|