Cleanup - WIP
This commit is contained in:
27
peer/init.go
27
peer/init.go
@@ -78,10 +78,13 @@ func initFromHub(hubURL, apiKey string, privKey wgtypes.Key) (LocalState, error)
|
||||
return LocalState{}, fmt.Errorf("generate sign key: %w", err)
|
||||
}
|
||||
|
||||
body, _ := json.Marshal(m.PeerInitArgs{
|
||||
body, err := json.Marshal(m.PeerInitArgs{
|
||||
WGPubKey: wgPubKey[:],
|
||||
SignPubKey: signPubKey[:],
|
||||
})
|
||||
if err != nil {
|
||||
return LocalState{}, fmt.Errorf("json error: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, hubURL+"/peer/init/", bytes.NewReader(body))
|
||||
if err != nil {
|
||||
@@ -126,31 +129,15 @@ func initFromHub(hubURL, apiKey string, privKey wgtypes.Key) (LocalState, error)
|
||||
return LocalState{}, fmt.Errorf("hub init: no peer for own IP: %d", r.PeerIP)
|
||||
}
|
||||
|
||||
var isRelay, public bool
|
||||
var wgPort uint16
|
||||
|
||||
var ep4, ep6 netip.AddrPort
|
||||
if len(self.Addr4) > 0 {
|
||||
if addr, ok := netip.AddrFromSlice(self.Addr4); ok {
|
||||
ep4 = netip.AddrPortFrom(addr.Unmap(), self.Port)
|
||||
}
|
||||
}
|
||||
if len(self.Addr6) > 0 {
|
||||
if addr, ok := netip.AddrFromSlice(self.Addr6); ok {
|
||||
ep6 = netip.AddrPortFrom(addr.Unmap(), self.Port)
|
||||
}
|
||||
}
|
||||
public = ep4.IsValid() || ep6.IsValid()
|
||||
isRelay = self.Relay && public
|
||||
wgPort = self.Port
|
||||
public := self.IsPublic()
|
||||
|
||||
return LocalState{
|
||||
PrivKey: privKey,
|
||||
SignKey: *signPrivKey,
|
||||
VPNIP: vpnIP,
|
||||
VPNNet: vpnNet,
|
||||
WGPort: wgPort,
|
||||
IsRelay: isRelay,
|
||||
WGPort: self.Port,
|
||||
IsRelay: self.Relay && public,
|
||||
IsPublic: public,
|
||||
LocalDomain: r.LocalDomain,
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user