This commit is contained in:
jdl
2024-12-12 21:11:17 +01:00
parent 03ff1aac80
commit fdf0066fc2
35 changed files with 1138 additions and 331 deletions

View File

@@ -4,14 +4,15 @@ import (
"io"
"log"
"net"
"net/netip"
)
type Peer struct {
// Immutable data.
ip byte // Last byte of IPv4 address.
hubAddr string
apiKey string
ip byte // Last byte of IPv4 address.
hubAddr string
apiKey string
isServer bool
isMediator bool
encPubKey []byte
encPrivKey []byte
signPubKey []byte
@@ -31,6 +32,7 @@ func NewPeer(netName, listenIP string, port uint16) (*Peer, error) {
peer := &Peer{
ip: conf.PeerIP,
hubAddr: conf.HubAddress,
isMediator: conf.Mediator,
apiKey: conf.APIKey,
encPubKey: conf.EncPubKey,
encPrivKey: conf.EncPrivKey,
@@ -38,16 +40,16 @@ func NewPeer(netName, listenIP string, port uint16) (*Peer, error) {
signPrivKey: conf.SignPrivKey,
}
peer.router = NewRouter(conf)
_, peer.isServer = netip.AddrFromSlice(conf.PublicIP)
port = determinePort(conf.Port, port)
conn, err := openUDPConn(listenIP, port)
peer.conn, err = openUDPConn(listenIP, port)
if err != nil {
return nil, err
}
peer.conn = conn
peer.router = NewRouter(conf, peer.conn)
peer.iface, err = openInterface(conf.Network, conf.PeerIP, netName)
if err != nil {