/*
GoVPN -- simple secure free software virtual private network daemon
-Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2017 Sergey Matveev <stargrave@stargrave.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
"cypherpunks.ru/govpn"
)
+// Protocol is a GoVPN supported protocol: UDP, TCP or both
type Protocol int
const (
+ // ProtocolUDP GoVPN over UDP
ProtocolUDP Protocol = iota
+ // ProtocolTCP GoVPN over TCP
ProtocolTCP
)
+// Configuration hold GoVPN client configuration
type Configuration struct {
PrivateKey *[ed25519.PrivateKeySize]byte
Peer *govpn.PeerConf
MTU int
}
+// Validate return an error if a configuration is invalid
func (c *Configuration) Validate() error {
if c.MTU > govpn.MTUMax {
return fmt.Errorf("Invalid MTU %d, maximum allowable is %d", c.MTU, govpn.MTUMax)
return len(c.ProxyAddress) > 0
}
+// Client is a GoVPN client
type Client struct {
idsCache *govpn.MACCache
tap *govpn.TAP
Error chan error
}
+// MainCycle main loop of a connecting/connected client
func (c *Client) MainCycle() {
var err error
c.tap, err = govpn.TAPListen(c.config.InterfaceName, c.config.MTU)
}
}
+// NewClient return a configured GoVPN client, to trigger connection MainCycle must be executed
func NewClient(conf Configuration, verifier *govpn.Verifier, termSignal chan os.Signal) *Client {
client := Client{
idsCache: govpn.NewMACCache(),
termSignal: termSignal,
Error: make(chan error, 1),
}
- confs := map[govpn.PeerId]*govpn.PeerConf{*verifier.Id: conf.Peer}
+ confs := map[govpn.PeerID]*govpn.PeerConf{*verifier.ID: conf.Peer}
client.idsCache.Update(&confs)
return &client
}