mirror of
https://github.com/fosrl/newt.git
synced 2026-03-10 12:46:38 +00:00
Support relay switch
This commit is contained in:
31
wg/wg.go
31
wg/wg.go
@@ -419,18 +419,29 @@ func (s *WireGuardService) addPeer(peer Peer) error {
|
|||||||
}
|
}
|
||||||
// add keep alive using *time.Duration of 1 second
|
// add keep alive using *time.Duration of 1 second
|
||||||
keepalive := time.Second
|
keepalive := time.Second
|
||||||
// endpoint, err := net.ResolveUDPAddr("udp", peer.Endpoint)
|
|
||||||
// if err != nil {
|
|
||||||
// return fmt.Errorf("failed to resolve endpoint address: %w", err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// make the endpoint localhost to test
|
var peerConfig wgtypes.PeerConfig
|
||||||
|
if peer.Endpoint != "" {
|
||||||
|
endpoint, err := net.ResolveUDPAddr("udp", peer.Endpoint)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to resolve endpoint address: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
peerConfig := wgtypes.PeerConfig{
|
// make the endpoint localhost to test
|
||||||
PublicKey: pubKey,
|
|
||||||
AllowedIPs: allowedIPs,
|
peerConfig = wgtypes.PeerConfig{
|
||||||
PersistentKeepaliveInterval: &keepalive,
|
PublicKey: pubKey,
|
||||||
// Endpoint: endpoint,
|
AllowedIPs: allowedIPs,
|
||||||
|
PersistentKeepaliveInterval: &keepalive,
|
||||||
|
Endpoint: endpoint,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
peerConfig = wgtypes.PeerConfig{
|
||||||
|
PublicKey: pubKey,
|
||||||
|
AllowedIPs: allowedIPs,
|
||||||
|
PersistentKeepaliveInterval: &keepalive,
|
||||||
|
}
|
||||||
|
logger.Info("Added peer with no endpoint!")
|
||||||
}
|
}
|
||||||
|
|
||||||
config := wgtypes.Config{
|
config := wgtypes.Config{
|
||||||
|
|||||||
Reference in New Issue
Block a user