]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/cypherpunks.ru/govpn/cmd/govpn-client/main.go
Use RFC 5424-like structured log format
[govpn.git] / src / cypherpunks.ru / govpn / cmd / govpn-client / main.go
index b46a16eb93203cb93a7002d372b24b64de050602..38bdae3bec704dd0e099bb9b7b0771577106052f 100644 (file)
@@ -21,6 +21,7 @@ package main
 
 import (
        "flag"
+       "fmt"
        "log"
        "net"
        "os"
@@ -43,10 +44,13 @@ var (
        proxyAuth   = flag.String("proxy-auth", "", "user:password Basic proxy auth")
        mtu         = flag.Int("mtu", govpn.MTUDefault, "MTU of TAP interface")
        timeoutP    = flag.Int("timeout", 60, "Timeout seconds")
+       timeSync    = flag.Int("timesync", 0, "Time synchronization requirement")
        noisy       = flag.Bool("noise", false, "Enable noise appending")
        encless     = flag.Bool("encless", false, "Encryptionless mode")
        cpr         = flag.Int("cpr", 0, "Enable constant KiB/sec out traffic rate")
        egdPath     = flag.String("egd", "", "Optional path to EGD socket")
+       syslog      = flag.Bool("syslog", false, "Enable logging to syslog")
+       warranty    = flag.Bool("warranty", false, "Print warranty information")
 
        conf        *govpn.PeerConf
        tap         *govpn.TAP
@@ -58,6 +62,10 @@ var (
 
 func main() {
        flag.Parse()
+       if *warranty {
+               fmt.Println(govpn.Warranty)
+               return
+       }
        timeout = *timeoutP
        var err error
        log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
@@ -70,6 +78,9 @@ func main() {
                govpn.EGDInit(*egdPath)
        }
 
+       if *verifierRaw == "" {
+               log.Fatalln("No verifier specified")
+       }
        verifier, err := govpn.VerifierFromString(*verifierRaw)
        if err != nil {
                log.Fatalln(err)
@@ -90,13 +101,16 @@ func main() {
                Iface:    *ifaceName,
                MTU:      *mtu,
                Timeout:  time.Second * time.Duration(timeout),
+               TimeSync: *timeSync,
                Noise:    *noisy,
                CPR:      *cpr,
                Encless:  *encless,
                Verifier: verifier,
                DSAPriv:  priv,
        }
-       idsCache = govpn.NewCipherCache([]govpn.PeerId{*verifier.Id})
+       idsCache = govpn.NewCipherCache()
+       confs := map[govpn.PeerId]*govpn.PeerConf{*verifier.Id: conf}
+       idsCache.Update(&confs)
        log.Println(govpn.VersionGet())
 
        tap, err = govpn.TAPListen(*ifaceName, *mtu)
@@ -113,6 +127,10 @@ func main() {
                go govpn.StatsProcessor(statsPort, &knownPeers)
        }
 
+       if *syslog {
+               govpn.SyslogEnable()
+       }
+
        termSignal := make(chan os.Signal, 1)
        signal.Notify(termSignal, os.Interrupt, os.Kill)
 
@@ -138,7 +156,7 @@ MainCycle:
                }
                select {
                case <-termSignal:
-                       log.Fatalln("Finishing")
+                       govpn.BothPrintf(`[finish remote="%s"]`, *remoteAddr)
                        termination <- struct{}{}
                        break MainCycle
                case <-timeouted:
@@ -149,5 +167,5 @@ MainCycle:
                close(rehandshaking)
                close(termination)
        }
-       govpn.ScriptCall(*downPath, *ifaceName)
+       govpn.ScriptCall(*downPath, *ifaceName, *remoteAddr)
 }