X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcypherpunks.ru%2Fgovpn%2Fclient%2Fclient.go;h=60e115dd1b2ebe7821fb72758fa9652a485de7ba;hb=9f7abcad309afd709a1f16cdf961837bb9510036;hp=8102cc6cdf1430217a27052526496b8c8af446a4;hpb=0348b54d1c83feca398182e9a86a2a92ed428447;p=govpn.git diff --git a/src/cypherpunks.ru/govpn/client/client.go b/src/cypherpunks.ru/govpn/client/client.go index 8102cc6..60e115d 100644 --- a/src/cypherpunks.ru/govpn/client/client.go +++ b/src/cypherpunks.ru/govpn/client/client.go @@ -30,13 +30,17 @@ import ( "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 @@ -52,6 +56,7 @@ type Configuration struct { 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) @@ -69,6 +74,7 @@ func (c *Configuration) isProxy() bool { return len(c.ProxyAddress) > 0 } +// Client is a GoVPN client type Client struct { idsCache *govpn.MACCache tap *govpn.TAP @@ -85,6 +91,7 @@ type Client struct { 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) @@ -146,6 +153,7 @@ MainCycle: } } +// 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(),