newcfg function call
This commit is contained in:
10
main.go
10
main.go
@@ -18,6 +18,8 @@ type server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *server) Ping(ctx context.Context, req *pb.PingRequest) (*pb.PingResponse, error) {
|
func (s *server) Ping(ctx context.Context, req *pb.PingRequest) (*pb.PingResponse, error) {
|
||||||
|
key, _ := wgtypes.GeneratePrivateKey()
|
||||||
|
newcfg(s.wgClient, key.PublicKey())
|
||||||
return &pb.PingResponse{Reply: "Pong: " + req.Message}, nil
|
return &pb.PingResponse{Reply: "Pong: " + req.Message}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,17 +43,13 @@ func main() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newcfg(client *wgctrl.Client, pubkey string) {
|
func newcfg(client *wgctrl.Client, pubkey wgtypes.Key) {
|
||||||
peerPubKey, err := wgtypes.ParseKey(pubkey)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("invalid peer public key: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
allowedIP1 := net.IPNet{IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(32, 32)}
|
allowedIP1 := net.IPNet{IP: net.ParseIP("10.0.0.3"), Mask: net.CIDRMask(32, 32)}
|
||||||
persistentKeepalive := 25 * time.Second
|
persistentKeepalive := 25 * time.Second
|
||||||
|
|
||||||
peerCfg := wgtypes.PeerConfig{
|
peerCfg := wgtypes.PeerConfig{
|
||||||
PublicKey: peerPubKey,
|
PublicKey: pubkey,
|
||||||
AllowedIPs: []net.IPNet{allowedIP1},
|
AllowedIPs: []net.IPNet{allowedIP1},
|
||||||
PersistentKeepaliveInterval: &persistentKeepalive,
|
PersistentKeepaliveInterval: &persistentKeepalive,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user