WIP
This commit is contained in:
18
peer/peer.go
18
peer/peer.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user