mirror of
https://github.com/netbirdio/netbird.git
synced 2025-05-29 22:31:50 +02:00
refactor: rename SignalExchangeServer to Server to comply with good practices
This commit is contained in:
parent
94c0091a7b
commit
9308a51800
@ -12,20 +12,20 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SignalExchangeServer an instance of a Signal server
|
// Server an instance of a Signal server
|
||||||
type SignalExchangeServer struct {
|
type Server struct {
|
||||||
registry *peer.Registry
|
registry *peer.Registry
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new Signal server
|
// NewServer creates a new Signal server
|
||||||
func NewServer() *SignalExchangeServer {
|
func NewServer() *Server {
|
||||||
return &SignalExchangeServer{
|
return &Server{
|
||||||
registry: peer.NewRegistry(),
|
registry: peer.NewRegistry(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send forwards a message to the signal peer
|
// Send forwards a message to the signal peer
|
||||||
func (s *SignalExchangeServer) Send(ctx context.Context, msg *proto.EncryptedMessage) (*proto.EncryptedMessage, error) {
|
func (s *Server) Send(ctx context.Context, msg *proto.EncryptedMessage) (*proto.EncryptedMessage, error) {
|
||||||
|
|
||||||
if !s.registry.IsPeerRegistered(msg.Key) {
|
if !s.registry.IsPeerRegistered(msg.Key) {
|
||||||
return nil, fmt.Errorf("unknown peer %s", msg.Key)
|
return nil, fmt.Errorf("unknown peer %s", msg.Key)
|
||||||
@ -46,7 +46,7 @@ func (s *SignalExchangeServer) Send(ctx context.Context, msg *proto.EncryptedMes
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConnectStream connects to the exchange stream
|
// ConnectStream connects to the exchange stream
|
||||||
func (s *SignalExchangeServer) ConnectStream(stream proto.SignalExchange_ConnectStreamServer) error {
|
func (s *Server) ConnectStream(stream proto.SignalExchange_ConnectStreamServer) error {
|
||||||
p, err := s.connectPeer(stream)
|
p, err := s.connectPeer(stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -82,7 +82,7 @@ func (s *SignalExchangeServer) ConnectStream(stream proto.SignalExchange_Connect
|
|||||||
// Handles initial Peer connection.
|
// Handles initial Peer connection.
|
||||||
// Each connection must provide an ID header.
|
// Each connection must provide an ID header.
|
||||||
// At this moment the connecting Peer will be registered in the peer.Registry
|
// At this moment the connecting Peer will be registered in the peer.Registry
|
||||||
func (s SignalExchangeServer) connectPeer(stream proto.SignalExchange_ConnectStreamServer) (*peer.Peer, error) {
|
func (s Server) connectPeer(stream proto.SignalExchange_ConnectStreamServer) (*peer.Peer, error) {
|
||||||
if meta, hasMeta := metadata.FromIncomingContext(stream.Context()); hasMeta {
|
if meta, hasMeta := metadata.FromIncomingContext(stream.Context()); hasMeta {
|
||||||
if id, found := meta[proto.HeaderId]; found {
|
if id, found := meta[proto.HeaderId]; found {
|
||||||
p := peer.NewPeer(id[0], stream)
|
p := peer.NewPeer(id[0], stream)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user