netbird/relay/server/peer.go

34 lines
489 B
Go
Raw Normal View History

2024-05-17 17:43:28 +02:00
package server
import (
"net"
log "github.com/sirupsen/logrus"
2024-05-23 13:24:02 +02:00
"github.com/netbirdio/netbird/relay/messages"
)
2024-05-17 17:43:28 +02:00
type Peer struct {
Log *log.Entry
2024-05-23 13:24:02 +02:00
idS string
idB []byte
2024-05-17 17:43:28 +02:00
conn net.Conn
}
2024-05-23 13:24:02 +02:00
func NewPeer(id []byte, conn net.Conn) *Peer {
stringID := messages.HashIDToString(id)
2024-05-17 17:43:28 +02:00
return &Peer{
2024-05-23 13:24:02 +02:00
Log: log.WithField("peer_id", stringID),
idB: id,
idS: stringID,
conn: conn,
2024-05-17 17:43:28 +02:00
}
}
2024-05-23 13:24:02 +02:00
func (p *Peer) ID() []byte {
return p.idB
2024-05-17 17:43:28 +02:00
}
2024-05-23 13:24:02 +02:00
func (p *Peer) String() string {
return p.idS
2024-05-17 17:43:28 +02:00
}