]> Cypherpunks.ru repositories - govpn.git/commitdiff
Split long lines
authorSergey Matveev <stargrave@stargrave.org>
Sat, 25 Feb 2017 12:39:26 +0000 (15:39 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 3 Mar 2017 21:02:13 +0000 (00:02 +0300)
14 files changed:
src/cypherpunks.ru/govpn/client/client.go
src/cypherpunks.ru/govpn/client/tcp.go
src/cypherpunks.ru/govpn/cmd/govpn-client/main.go
src/cypherpunks.ru/govpn/cmd/govpn-server/action.go
src/cypherpunks.ru/govpn/cmd/govpn-server/conf.go
src/cypherpunks.ru/govpn/cmd/govpn-server/main.go
src/cypherpunks.ru/govpn/common.go
src/cypherpunks.ru/govpn/identity.go
src/cypherpunks.ru/govpn/peer.go
src/cypherpunks.ru/govpn/server/common.go
src/cypherpunks.ru/govpn/server/server.go
src/cypherpunks.ru/govpn/server/tcp.go
src/cypherpunks.ru/govpn/server/udp.go
src/cypherpunks.ru/govpn/stats.go

index 4ebd8a98fa47e1eb5955971f2d1c83c47e20dfe6..ef832af8fbc5c55f3a8f460b369a0d69b0c90446 100644 (file)
@@ -48,7 +48,11 @@ type Configuration struct {
 // Validate returns an error if a configuration is invalid
 func (c *Configuration) Validate() error {
        if c.Peer.MTU > govpn.MTUMax {
-               return errors.Errorf("Invalid MTU %d, maximum allowable is %d", c.Peer.MTU, govpn.MTUMax)
+               return errors.Errorf(
+                       "Invalid MTU %d, maximum allowable is %d",
+                       c.Peer.MTU,
+                       govpn.MTUMax,
+               )
        }
        if len(c.RemoteAddress) == 0 {
                return errors.New("Missing RemoteAddress")
@@ -78,7 +82,9 @@ func (c *Configuration) LogFields() logrus.Fields {
                f[prefix+"proxy"] = c.ProxyAddress
        }
        if c.FileDescriptor > 0 {
-               f[prefix+"remote"] = fmt.Sprintf("fd:%d(%s)", c.FileDescriptor, c.RemoteAddress)
+               f[prefix+"remote"] = fmt.Sprintf(
+                       "fd:%d(%s)", c.FileDescriptor, c.RemoteAddress,
+               )
        } else {
                f[prefix+"remote"] = c.RemoteAddress
        }
@@ -154,7 +160,11 @@ func (c *Client) KnownPeers() *govpn.KnownPeers {
 func (c *Client) MainCycle() {
        var err error
        l := c.logger.WithFields(logrus.Fields{"func": logFuncPrefix + "Client.MainCycle"})
-       l.WithFields(c.LogFields()).WithFields(c.config.LogFields()).Info("Starting...")
+       l.WithFields(
+               c.LogFields(),
+       ).WithFields(
+               c.config.LogFields(),
+       ).Info("Starting...")
 
        // if available, run PreUp, it might create interface
        if c.config.Peer.PreUp != nil {
index eca48521bc446eb84f846634dd5c4542ddcaf831..0832e11b17148ed7ae311e0b1ad30a30bcc26a9f 100644 (file)
@@ -103,7 +103,9 @@ HandshakeCycle:
                }
                n, err = conn.Read(buf[prev:])
                if err != nil {
-                       c.logger.WithFields(fields).WithFields(
+                       c.logger.WithFields(
+                               fields,
+                       ).WithFields(
                                c.LogFields(),
                        ).Debug("Packet timeouted")
                        c.timeouted <- struct{}{}
@@ -113,7 +115,9 @@ HandshakeCycle:
                prev += n
                _, err = c.idsCache.Find(buf[:prev])
                if err != nil {
-                       c.logger.WithFields(fields).WithFields(
+                       c.logger.WithFields(
+                               fields,
+                       ).WithFields(
                                c.LogFields(),
                        ).WithError(err).Debug("Can't find peer in ids")
                        continue
@@ -121,7 +125,11 @@ HandshakeCycle:
                peer, err = hs.Client(buf[:prev])
                prev = 0
                if err != nil {
-                       c.logger.WithFields(fields).WithError(err).WithFields(
+                       c.logger.WithFields(
+                               fields,
+                       ).WithError(
+                               err,
+                       ).WithFields(
                                c.LogFields(),
                        ).Debug("Can't create new peer")
                        continue
@@ -157,7 +165,9 @@ TransportCycle:
                default:
                }
                if prev == len(buf) {
-                       c.logger.WithFields(c.LogFields()).Debug("Packet timeouted")
+                       c.logger.WithFields(
+                               c.LogFields(),
+                       ).Debug("Packet timeouted")
                        c.timeouted <- struct{}{}
                        break TransportCycle
                }
@@ -167,7 +177,11 @@ TransportCycle:
                }
                n, err = conn.Read(buf[prev:])
                if err != nil {
-                       c.logger.WithError(err).WithFields(c.LogFields()).Debug("Connection timeouted")
+                       c.logger.WithError(
+                               err,
+                       ).WithFields(
+                               c.LogFields(),
+                       ).Debug("Connection timeouted")
                        c.timeouted <- struct{}{}
                        break TransportCycle
                }
index bd8b0678b1eca147079db371fac697e5d34c9ef6..a3399ab8ead7921e830c021697b294f3ac4c8453 100644 (file)
@@ -80,7 +80,13 @@ func main() {
        }
 
        if protocol, err = govpn.NewProtocolFromString(*proto); err != nil {
-               logger.WithError(err).WithFields(fields).WithField("proto", *proto).Fatal("Invalid protocol")
+               logger.WithError(
+                       err,
+               ).WithFields(
+                       fields,
+               ).WithField(
+                       "proto", *proto,
+               ).Fatal("Invalid protocol")
        }
 
        if *proxyAddr != "" && protocol == govpn.ProtocolUDP {
index f5fde8b53a803f2b4565807f55e360f125ea37a0..751081a83c97232448d9c1fb79a6ffa78fedfe92 100644 (file)
@@ -1,6 +1,7 @@
 /*
 GoVPN -- simple secure free software virtual private network daemon
 Copyright (C) 2014-2017 Sergey Matveev <stargrave@stargrave.org>
+              2016-2017 Bruno Clermont <bruno@robotinfra.com>
 
 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
index 80581ab4418db9ec8474aeab8ef24664525fdcc3..d357b2536c9d25158943a2f363b0113761a27ba6 100644 (file)
@@ -125,7 +125,12 @@ func confRefresh() error {
                return errors.Wrap(err, "confRead")
        }
        confs = *newConfs
-       logger.WithFields(fields).WithField("newConfs", len(confs)).Debug("idsCache.Update")
+       logger.WithFields(
+               fields,
+       ).WithField(
+               "newConfs",
+               len(confs),
+       ).Debug("idsCache.Update")
        if err = idsCache.Update(newConfs); err != nil {
                return errors.Wrap(err, "idsCache.Update")
        }
@@ -138,13 +143,17 @@ func confInit() {
        err := confRefresh()
        fields := logrus.Fields{"func": "confInit"}
        if err != nil {
-               logger.WithError(err).WithFields(fields).Fatal("Couldn't perform initial configuration read")
+               logger.WithError(err).WithFields(
+                       fields,
+               ).Fatal("Couldn't perform initial configuration read")
        }
        go func() {
                for {
                        time.Sleep(refreshRate)
                        if err = confRefresh(); err != nil {
-                               logger.WithError(err).WithFields(fields).Error("Couldn't refresh configuration")
+                               logger.WithError(err).WithFields(
+                                       fields,
+                               ).Error("Couldn't refresh configuration")
                        }
                }
        }()
index 2c7026754334411fd45ffeca70c468d5556b309b..a60e5a01cd38251818b0ec2b6d455c78a06b8402 100644 (file)
@@ -58,12 +58,18 @@ func main() {
 
        logger, err = govpn.NewLogger(*logLevel, *syslog)
        if err != nil {
-               logrus.WithFields(fields).WithError(err).Fatal("Couldn't initialize logging")
+               logrus.WithFields(
+                       fields,
+               ).WithError(err).Fatal("Couldn't initialize logging")
        }
        govpn.SetLogger(logger)
 
        if *egdPath != "" {
-               logger.WithField("egd_path", *egdPath).WithFields(fields).Debug("Init EGD")
+               logger.WithField(
+                       "egd_path", *egdPath,
+               ).WithFields(
+                       fields,
+               ).Debug("Init EGD")
                govpn.EGDInit(*egdPath)
        }
 
@@ -75,13 +81,23 @@ func main() {
                Timeout:      govpn.TimeoutDefault,
        }
        if serverConfig.Protocol, err = govpn.NewProtocolFromString(*proto); err != nil {
-               logger.WithError(err).WithFields(fields).WithField("proto", *proto).Fatal("Invalid protocol")
+               logger.WithError(err).WithFields(
+                       fields,
+               ).WithField(
+                       "proto", *proto,
+               ).Fatal("Invalid protocol")
        }
        if err = serverConfig.Validate(); err != nil {
                logger.WithError(err).WithFields(fields).Fatal("Invalid configuration")
        }
 
-       srv := server.NewServer(serverConfig, confs, idsCache, logger, govpn.CatchSignalShutdown())
+       srv := server.NewServer(
+               serverConfig,
+               confs,
+               idsCache,
+               logger,
+               govpn.CatchSignalShutdown(),
+       )
 
        if *stats != "" {
                go govpn.StatsProcessor(*stats, srv.KnownPeers())
index 3fe31651baaeecce97feac2ca017aa70f34e9524..684491cfd950516aab0ad412bba1932f84293c36 100644 (file)
@@ -140,7 +140,9 @@ func NewProtocolFromString(p string) (Protocol, error) {
                index++
        }
 
-       return Protocol(-1), errors.Errorf("Invalid protocol %q: %s", p, strings.Join(choices, ","))
+       return Protocol(-1), errors.Errorf(
+               "Invalid protocol %q: %s", p, strings.Join(choices, ","),
+       )
 }
 
 // SliceZero zeros each byte.
index 81066bc715abbe961eb9225d60ee3dfd2b2b94b5..db338f0348c98b9e5593c17872664e663e9eda17 100644 (file)
@@ -86,7 +86,12 @@ func (mc *MACCache) Update(peers *map[PeerID]*PeerConf) error {
                        delete(mc.cache, pid)
                }
        }
-       logger.WithFields(fields).WithField("size", mc.Length()).Debug("Cleaned, add/update new key")
+       logger.WithFields(
+               fields,
+       ).WithField(
+               "size",
+               mc.Length(),
+       ).Debug("Cleaned, add/update new key")
        for pid, pc := range *peers {
                if _, exists := mc.cache[pid]; exists {
                        logger.WithFields(fields).WithFields(
@@ -133,7 +138,12 @@ func AddTimeSync(ts int, data []byte) {
        for i := 0; i < 8; i++ {
                data[i] ^= buf[i]
        }
-       logger.WithFields(fields).WithField("after", hex.EncodeToString(data)).Debug("Done")
+       logger.WithFields(
+               fields,
+       ).WithField(
+               "after",
+               hex.EncodeToString(data),
+       ).Debug("Done")
 }
 
 // Find tries to find peer's identity (that equals to MAC)
@@ -166,7 +176,12 @@ func (mc *MACCache) Find(data []byte) (*PeerID, error) {
                        mt.l.Unlock()
                        return nil, errors.Wrap(err, "mt.mac.Write")
                }
-               logger.WithFields(fields).WithField("buf", hex.EncodeToString(buf[:0])).Debug("mt.mac.Sum")
+               logger.WithFields(
+                       fields,
+               ).WithField(
+                       "buf",
+                       hex.EncodeToString(buf[:0]),
+               ).Debug("mt.mac.Sum")
                mt.mac.Sum(sum[:0])
                mt.l.Unlock()
 
index b466161be989b38e0a7c1fce89211c87529e56dc..e914cd69f5216903a718a5aaa2ea92bcab1dcd5e 100644 (file)
@@ -294,14 +294,17 @@ func newPeer(isClient bool, addr string, conn io.Writer, conf *PeerConf, key *[S
 func (p *Peer) EthProcess(data []byte) error {
        const paddingSize = 1
        if len(data) > p.MTU-paddingSize {
-               logger.WithFields(p.LogFields()).WithFields(
+               logger.WithFields(
+                       p.LogFields(),
+               ).WithFields(
                        p.ConfigurationLogFields(),
                ).WithFields(
                        logrus.Fields{
                                "func":        logFuncPrefix + "Peer.EthProcess",
                                "padding":     paddingSize,
                                "packet_size": len(data),
-                       }).Warning("Ignore padded data packet larger than MTU")
+                       },
+               ).Warning("Ignore padded data packet larger than MTU")
                return nil
        }
        p.BusyT.Lock()
@@ -362,8 +365,13 @@ func (p *Peer) PktProcess(data []byte, tap io.Writer, reorderable bool) bool {
                "data":        len(data),
        }
        if len(data) < MinPktLength {
-               logger.WithFields(p.LogFields()).WithFields(fields).WithField(
-                       "minimum_packet_Length", MinPktLength,
+               logger.WithFields(
+                       p.LogFields(),
+               ).WithFields(
+                       fields,
+               ).WithField(
+                       "minimum_packet_Length",
+                       MinPktLength,
                ).Debug("Ignore packet smaller than allowed minimum")
                return false
        }
@@ -377,7 +385,9 @@ func (p *Peer) PktProcess(data []byte, tap io.Writer, reorderable bool) bool {
                var err error
                out, err = EnclessDecode(p.key, p.nonceR, data[:len(data)-NonceSize])
                if err != nil {
-                       logger.WithFields(p.LogFields()).WithError(err).Debug("Failed to decode encless")
+                       logger.WithFields(
+                               p.LogFields(),
+                       ).WithError(err).Debug("Failed to decode encless")
                        p.FramesUnauth++
                        p.BusyR.Unlock()
                        return false
@@ -504,7 +514,9 @@ func PeerTapProcessor(peer *Peer, tap *TAP, terminator chan struct{}) {
                                }
                        case data = <-tap.Sink:
                                if err = peer.EthProcess(data); err != nil {
-                                       logger.WithFields(fields).WithFields(
+                                       logger.WithFields(
+                                               fields,
+                                       ).WithFields(
                                                peer.LogFields(),
                                        ).WithError(err).Warn("Can't process ethernet packet")
                                }
@@ -520,7 +532,9 @@ func PeerTapProcessor(peer *Peer, tap *TAP, terminator chan struct{}) {
                                break CPRProcessor
                        case data = <-tap.Sink:
                                if err = peer.EthProcess(data); err != nil {
-                                       logger.WithFields(fields).WithFields(
+                                       logger.WithFields(
+                                               fields,
+                                       ).WithFields(
                                                peer.LogFields(),
                                        ).WithError(err).Warn("Can't process ethernet packet")
                                }
@@ -528,7 +542,9 @@ func PeerTapProcessor(peer *Peer, tap *TAP, terminator chan struct{}) {
                        }
                        if data == nil {
                                if err = peer.EthProcess(nil); err != nil {
-                                       logger.WithFields(fields).WithFields(
+                                       logger.WithFields(
+                                               fields,
+                                       ).WithFields(
                                                peer.LogFields(),
                                        ).WithError(err).Warn("Can't process nil ethernet packet")
                                }
index 76ccfedd5b8c8fb64b5e29e06099f17dc3e29ca9..9a5554bda2d0429906edb456ab04069635e4b93d 100644 (file)
@@ -42,7 +42,12 @@ func (s *Server) callUp(peer *govpn.Peer, proto govpn.Protocol) (*govpn.TAP, err
        fields["func"] = logFuncPrefix + "Server.callUp"
 
        if !isConfigIface && conf.PreUp == nil {
-               return nil, errors.Wrapf(errMisconfiguredTap, "interface:%q, PreUp:%q", conf.Iface, conf.PreUp)
+               return nil, errors.Wrapf(
+                       errMisconfiguredTap,
+                       "interface:%q, PreUp:%q",
+                       conf.Iface,
+                       conf.PreUp,
+               )
        }
 
        if conf.PreUp != nil {
index 76f8ee3222fe15764dff742599b37d7a17fa8ded..ef53b8f626e25e79a3ba292dab75f0175808e7e2 100644 (file)
@@ -28,12 +28,14 @@ import (
        "cypherpunks.ru/govpn"
 )
 
-// PeerConfigurer is used by a GoVPN server to figure the configuration of a single peer
+// PeerConfigurer is used by a GoVPN server to figure the configuration
+// of a single peer
 type PeerConfigurer interface {
        Get(govpn.PeerID) *govpn.PeerConf
 }
 
-// MACPeerFinder is used by GoVPN server to figure the PeerID from handshake data
+// MACPeerFinder is used by GoVPN server to figure the PeerID from
+// handshake data
 type MACPeerFinder interface {
        Find([]byte) (*govpn.PeerID, error)
 }
@@ -117,7 +119,8 @@ func (s *Server) KnownPeers() *govpn.KnownPeers {
        return &s.knownPeers
 }
 
-// NewServer return a configured GoVPN server, to listen network connection MainCycle must be executed
+// NewServer return a configured GoVPN server, to listen network
+// connection MainCycle must be executed
 func NewServer(serverConf Configuration, peerConfs PeerConfigurer, idsCache MACPeerFinder, logger *logrus.Logger, termSignal chan interface{}) *Server {
        govpn.SetLogger(logger)
        return &Server{
@@ -154,7 +157,13 @@ func (s *Server) MainCycle() {
        }
        fields := logrus.Fields{"func": logFuncPrefix + "Server.MainCycle"}
 
-       s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(s.configuration.LogFields()).Info("Starting...")
+       s.logger.WithFields(
+               fields,
+       ).WithFields(
+               s.LogFields(),
+       ).WithFields(
+               s.configuration.LogFields(),
+       ).Info("Starting...")
 
        var needsDeletion bool
        var err error
@@ -165,13 +174,27 @@ MainCycle:
        for {
                select {
                case <-s.termSignal:
-                       s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(s.configuration.LogFields()).Info("Terminating")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               s.LogFields(),
+                       ).WithFields(
+                               s.configuration.LogFields(),
+                       ).Info("Terminating")
                        for _, ps := range s.peers {
                                if err = s.callDown(ps); err != nil {
-                                       s.logger.WithFields(fields).WithError(err).WithFields(ps.peer.LogFields()).Error("Failed to run callDown")
+                                       s.logger.WithFields(
+                                               fields,
+                                       ).WithError(err).WithFields(
+                                               ps.peer.LogFields(),
+                                       ).Error("Failed to run callDown")
                                }
                                if err = ps.tap.Close(); err != nil {
-                                       logrus.WithError(err).WithFields(fields).WithFields(ps.peer.LogFields()).Error("Couldn't close TAP")
+                                       logrus.WithError(err).WithFields(
+                                               fields,
+                                       ).WithFields(
+                                               ps.peer.LogFields(),
+                                       ).Error("Couldn't close TAP")
                                }
                        }
                        // empty value signals that everything is fine
@@ -183,7 +206,11 @@ MainCycle:
                        s.hsLock.Lock()
                        for addr, hs := range s.handshakes {
                                if hs.LastPing.Add(s.configuration.Timeout).Before(now) {
-                                       logrus.WithFields(fields).WithFields(hs.LogFields()).Debug("handshake is expired, delete")
+                                       logrus.WithFields(
+                                               fields,
+                                       ).WithFields(
+                                               hs.LogFields(),
+                                       ).Debug("handshake is expired, delete")
                                        hs.Zero()
                                        delete(s.handshakes, addr)
                                }
@@ -193,18 +220,32 @@ MainCycle:
                        s.kpLock.Lock()
                        for addr, ps := range s.peers {
                                ps.peer.BusyR.Lock()
-                               needsDeletion = ps.peer.LastPing.Add(s.configuration.Timeout).Before(now)
+                               needsDeletion = ps.peer.LastPing.Add(
+                                       s.configuration.Timeout,
+                               ).Before(now)
                                ps.peer.BusyR.Unlock()
                                if needsDeletion {
-                                       logrus.WithFields(fields).WithFields(ps.peer.LogFields()).Info("Delete peer")
+                                       logrus.WithFields(
+                                               fields,
+                                       ).WithFields(
+                                               ps.peer.LogFields(),
+                                       ).Info("Delete peer")
                                        delete(s.peers, addr)
                                        delete(s.knownPeers, addr)
                                        delete(s.peersByID, *ps.peer.ID)
                                        if err = s.callDown(ps); err != nil {
-                                               logrus.WithError(err).WithFields(fields).WithFields(ps.peer.LogFields()).Error("Couldn't execute callDown")
+                                               logrus.WithError(err).WithFields(
+                                                       fields,
+                                               ).WithFields(
+                                                       ps.peer.LogFields(),
+                                               ).Error("Couldn't execute callDown")
                                        }
                                        if err = ps.tap.Close(); err != nil {
-                                               logrus.WithError(err).WithFields(fields).WithFields(ps.peer.LogFields()).Error("Couldn't close TAP")
+                                               logrus.WithError(err).WithFields(
+                                                       fields,
+                                               ).WithFields(
+                                                       ps.peer.LogFields(),
+                                               ).Error("Couldn't close TAP")
                                        }
                                        ps.terminator <- struct{}{}
                                }
index 28528a0a1423a2cac4c39621a95a30d803f4ae1d..59eda53cb72b4bd3c16ccd7ff542312e342b0787 100644 (file)
@@ -44,12 +44,22 @@ func (s *Server) startTCP() {
                "func": logFuncPrefix + "Server.startTCP",
                "bind": bind.String(),
        }
-       s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(s.configuration.LogFields()).Info("Listen")
+       s.logger.WithFields(
+               fields,
+       ).WithFields(
+               s.LogFields(),
+       ).WithFields(
+               s.configuration.LogFields(),
+       ).Info("Listen")
        go func() {
                for {
                        conn, err := listener.AcceptTCP()
                        if err != nil {
-                               s.logger.WithError(err).WithFields(fields).WithFields(s.LogFields()).Error("Failed to accept TCP connection")
+                               s.logger.WithError(err).WithFields(
+                                       fields,
+                               ).WithFields(
+                                       s.LogFields(),
+                               ).Error("Failed to accept TCP connection")
                                continue
                        }
                        go s.handleTCP(conn)
@@ -86,13 +96,23 @@ func (s *Server) handleTCP(conn net.Conn) {
                }
                n, err = conn.Read(buf[prev:])
                if err != nil {
-                       s.logger.WithFields(fields).WithFields(s.LogFields()).WithError(err).Debug("Can't read connection: either EOFed or timeouted")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               s.LogFields(),
+                       ).WithError(
+                               err,
+                       ).Debug("Can't read connection: either EOFed or timeouted")
                        break
                }
                prev += n
                peerID, err := s.idsCache.Find(buf[:prev])
                if err != nil {
-                       s.logger.WithFields(fields).WithFields(s.LogFields()).WithError(err).Debug("Couldn't lookup for peer in ids")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               s.LogFields(),
+                       ).WithError(err).Debug("Couldn't lookup for peer in ids")
                        continue
                }
                if peerID == nil {
@@ -102,14 +122,24 @@ func (s *Server) handleTCP(conn net.Conn) {
                if hs == nil {
                        conf = s.confs.Get(*peerID)
                        if conf == nil {
-                               s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(s.configuration.LogFields()).Error("Configuration get failed")
+                               s.logger.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       s.LogFields(),
+                               ).WithFields(
+                                       s.configuration.LogFields(),
+                               ).Error("Configuration get failed")
                                break
                        }
                        hs = govpn.NewHandshake(addr, conn, conf)
                }
                peer, err = hs.Server(buf[:prev])
                if err != nil {
-                       s.logger.WithFields(fields).WithError(err).WithFields(s.LogFields()).Error("Can't create new peer")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithError(err).WithFields(
+                               s.LogFields(),
+                       ).Error("Can't create new peer")
                        continue
                }
                prev = 0
@@ -117,7 +147,13 @@ func (s *Server) handleTCP(conn net.Conn) {
                        continue
                }
 
-               s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(peer.LogFields()).Info("Handshake completed")
+               s.logger.WithFields(
+                       fields,
+               ).WithFields(
+                       s.LogFields(),
+               ).WithFields(
+                       peer.LogFields(),
+               ).Info("Handshake completed")
 
                hs.Zero()
                s.peersByIDLock.RLock()
@@ -145,11 +181,23 @@ func (s *Server) handleTCP(conn net.Conn) {
                        s.peersLock.Unlock()
                        s.peersByIDLock.Unlock()
                        s.kpLock.Unlock()
-                       s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(peer.LogFields()).Debug("Rehandshake completed")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               s.LogFields(),
+                       ).WithFields(
+                               peer.LogFields(),
+                       ).Debug("Rehandshake completed")
                } else {
                        tap, err = s.callUp(peer, govpn.ProtocolTCP)
                        if err != nil {
-                               s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(peer.LogFields()).WithError(err).Error("TAP failed")
+                               s.logger.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       s.LogFields(),
+                               ).WithFields(
+                                       peer.LogFields(),
+                               ).WithError(err).Error("TAP failed")
                                peer = nil
                                break
                        }
@@ -169,7 +217,13 @@ func (s *Server) handleTCP(conn net.Conn) {
                        s.peersLock.Unlock()
                        s.peersByIDLock.Unlock()
                        s.kpLock.Unlock()
-                       s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(peer.LogFields()).Info("Peer created")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               s.LogFields(),
+                       ).WithFields(
+                               peer.LogFields(),
+                       ).Info("Peer created")
                }
                break
        }
@@ -193,7 +247,13 @@ func (s *Server) handleTCP(conn net.Conn) {
                }
                n, err = conn.Read(buf[prev:])
                if err != nil {
-                       s.logger.WithFields(fields).WithFields(s.LogFields()).WithError(err).Debug("Can't read connection: either EOFed or timeouted")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               s.LogFields(),
+                       ).WithError(
+                               err,
+                       ).Debug("Can't read connection: either EOFed or timeouted")
                        break
                }
                prev += n
@@ -206,7 +266,13 @@ func (s *Server) handleTCP(conn net.Conn) {
                        continue
                }
                if !peer.PktProcess(buf[:i+govpn.NonceSize], tap, false) {
-                       s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(peer.LogFields()).Warn("Packet unauthenticated")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               s.LogFields(),
+                       ).WithFields(
+                               peer.LogFields(),
+                       ).Warn("Packet unauthenticated")
                        break
                }
                copy(buf, buf[i+govpn.NonceSize:prev])
index a2d92af45b8ced46f435f90d075c2c0c2b46ac1d..c5793012e63e8cdaf7eecd479d1603c083398edd 100644 (file)
@@ -56,7 +56,13 @@ func (s *Server) startUDP() {
                "func": logFuncPrefix + "Server.startUDP",
                "bind": bind.String(),
        }
-       s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(s.configuration.LogFields()).Info("Listen")
+       s.logger.WithFields(
+               fields,
+       ).WithFields(
+               s.LogFields(),
+       ).WithFields(
+               s.configuration.LogFields(),
+       ).Info("Listen")
        udpBufs <- make([]byte, govpn.MTUMax)
        go func() {
                var buf []byte
@@ -75,18 +81,30 @@ func (s *Server) startUDP() {
                        buf = <-udpBufs
                        n, raddr, err = conn.ReadFromUDP(buf)
                        if err != nil {
-                               s.logger.WithFields(fields).WithFields(s.LogFields()).WithError(err).Debug("Receive failure")
+                               s.logger.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       s.LogFields(),
+                               ).WithError(err).Debug("Receive failure")
                                break
                        }
                        addr = raddr.String()
                        loopFields := logrus.Fields{"addr": addr}
 
-                       s.logger.WithFields(fields).WithFields(loopFields).Debug("Got UDP buffer, check if peer exists")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               loopFields,
+                       ).Debug("Got UDP buffer, check if peer exists")
                        s.peersLock.RLock()
                        ps, exists = s.peers[addr]
                        s.peersLock.RUnlock()
                        if exists {
-                               s.logger.WithFields(fields).WithFields(loopFields).Debug("Already known peer, PktProcess")
+                               s.logger.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       loopFields,
+                               ).Debug("Already known peer, PktProcess")
                                go func(peer *govpn.Peer, tap *govpn.TAP, buf []byte, n int) {
                                        peer.PktProcess(buf[:n], tap, true)
                                        udpBufs <- buf
@@ -99,15 +117,31 @@ func (s *Server) startUDP() {
                        hs, exists = s.handshakes[addr]
                        s.hsLock.RUnlock()
                        if !exists {
-                               logrus.WithFields(fields).WithFields(loopFields).Debug("No handshake yet, try to figure peer ID")
+                               logrus.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       loopFields,
+                               ).Debug("No handshake yet, try to figure peer ID")
                                peerID, err = s.idsCache.Find(buf[:n])
                                if err != nil {
-                                       s.logger.WithFields(fields).WithFields(loopFields).WithFields(s.LogFields()).WithError(err).Debug("Couldn't lookup for peer in ids")
+                                       s.logger.WithFields(
+                                               fields,
+                                       ).WithFields(
+                                               loopFields,
+                                       ).WithFields(
+                                               s.LogFields(),
+                                       ).WithError(err).Debug("Couldn't lookup for peer in ids")
                                        udpBufs <- buf
                                        continue
                                }
                                if peerID == nil {
-                                       s.logger.WithFields(fields).WithFields(loopFields).WithFields(s.LogFields()).Debug("Identity unknown")
+                                       s.logger.WithFields(
+                                               fields,
+                                       ).WithFields(
+                                               loopFields,
+                                       ).WithFields(
+                                               s.LogFields(),
+                                       ).Debug("Identity unknown")
                                        udpBufs <- buf
                                        continue
                                }
@@ -116,12 +150,24 @@ func (s *Server) startUDP() {
                                s.logger.WithFields(fields).WithFields(loopFields).Debug("Found peer ID")
                                conf = s.confs.Get(*peerID)
                                if conf == nil {
-                                       s.logger.WithFields(loopFields).WithFields(fields).WithFields(s.LogFields()).WithFields(s.configuration.LogFields()).Error("Peer try to connect, but not configured")
+                                       s.logger.WithFields(
+                                               loopFields,
+                                       ).WithFields(
+                                               fields,
+                                       ).WithFields(
+                                               s.LogFields(),
+                                       ).WithFields(
+                                               s.configuration.LogFields(),
+                                       ).Error("Peer try to connect, but not configured")
                                        udpBufs <- buf
                                        continue
                                }
 
-                               s.logger.WithFields(loopFields).WithFields(fields).Debug("Got configuration, perform handshake")
+                               s.logger.WithFields(
+                                       loopFields,
+                               ).WithFields(
+                                       fields,
+                               ).Debug("Got configuration, perform handshake")
                                hs = govpn.NewHandshake(
                                        addr,
                                        udpSender{conn: conn, addr: raddr},
@@ -130,10 +176,22 @@ func (s *Server) startUDP() {
                                _, err := hs.Server(buf[:n])
                                udpBufs <- buf
                                if err != nil {
-                                       s.logger.WithFields(loopFields).WithFields(fields).WithError(err).WithFields(s.LogFields()).Error("Can't create new peer: handshake failed")
+                                       s.logger.WithFields(
+                                               loopFields,
+                                       ).WithFields(
+                                               fields,
+                                       ).WithError(err).WithFields(
+                                               s.LogFields(),
+                                       ).Error("Can't create new peer: handshake failed")
                                        continue
                                }
-                               s.logger.WithFields(loopFields).WithFields(fields).WithFields(s.LogFields()).Info("Hashshake started, continue next packet")
+                               s.logger.WithFields(
+                                       loopFields,
+                               ).WithFields(
+                                       fields,
+                               ).WithFields(
+                                       s.LogFields(),
+                               ).Info("Hashshake started, continue next packet")
 
                                s.hsLock.Lock()
                                s.handshakes[addr] = hs
@@ -141,20 +199,44 @@ func (s *Server) startUDP() {
                                continue
                        }
 
-                       logrus.WithFields(fields).WithFields(loopFields).Debug("Already go handshake, finish it")
+                       logrus.WithFields(
+                               fields,
+                       ).WithFields(
+                               loopFields,
+                       ).Debug("Already go handshake, finish it")
                        peer, err := hs.Server(buf[:n])
                        if err != nil {
-                               s.logger.WithFields(fields).WithFields(loopFields).WithError(err).WithFields(s.LogFields()).Error("Can't create new peer: handshake failed")
+                               s.logger.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       loopFields,
+                               ).WithError(err).WithFields(
+                                       s.LogFields(),
+                               ).Error("Can't create new peer: handshake failed")
                                udpBufs <- buf
                                continue
                        }
                        if peer == nil {
-                               s.logger.WithFields(fields).WithFields(loopFields).WithFields(s.LogFields()).Error("Couldn't continue handshake")
+                               s.logger.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       loopFields,
+                               ).WithFields(
+                                       s.LogFields(),
+                               ).Error("Couldn't continue handshake")
                                udpBufs <- buf
                                continue
                        }
 
-                       s.logger.WithFields(fields).WithFields(s.LogFields()).WithFields(loopFields).WithFields(peer.LogFields()).Info("Handshake completed")
+                       s.logger.WithFields(
+                               fields,
+                       ).WithFields(
+                               s.LogFields(),
+                       ).WithFields(
+                               loopFields,
+                       ).WithFields(
+                               peer.LogFields(),
+                       ).Info("Handshake completed")
 
                        hs.Zero()
                        s.hsLock.Lock()
@@ -170,7 +252,11 @@ func (s *Server) startUDP() {
                        s.peersByIDLock.RUnlock()
 
                        if exists {
-                               s.logger.WithFields(fields).WithFields(loopFields).Debug("Peer already exists")
+                               s.logger.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       loopFields,
+                               ).Debug("Peer already exists")
                                s.peersLock.Lock()
                                s.peers[addrPrev].terminator <- struct{}{}
                                psNew := &PeerState{
@@ -197,13 +283,33 @@ func (s *Server) startUDP() {
                                s.peersByIDLock.Unlock()
                                s.kpLock.Unlock()
 
-                               s.logger.WithFields(fields).WithFields(loopFields).WithFields(s.LogFields()).WithFields(peer.LogFields()).Debug("Rehandshake completed")
+                               s.logger.WithFields(
+                                       fields,
+                               ).WithFields(
+                                       loopFields,
+                               ).WithFields(
+                                       s.LogFields(),
+                               ).WithFields(
+                                       peer.LogFields(),
+                               ).Debug("Rehandshake completed")
                        } else {
                                go func(addr string, peer *govpn.Peer) {
-                                       s.logger.WithFields(fields).WithFields(loopFields).Debug("Peer do not already exists")
+                                       s.logger.WithFields(
+                                               fields,
+                                       ).WithFields(
+                                               loopFields,
+                                       ).Debug("Peer do not already exists")
                                        tap, err := s.callUp(peer, govpn.ProtocolUDP)
                                        if err != nil {
-                                               s.logger.WithFields(loopFields).WithFields(fields).WithFields(s.LogFields()).WithFields(peer.LogFields()).WithError(err).Error("TAP failed")
+                                               s.logger.WithFields(
+                                                       loopFields,
+                                               ).WithFields(
+                                                       fields,
+                                               ).WithFields(
+                                                       s.LogFields(),
+                                               ).WithFields(
+                                                       peer.LogFields(),
+                                               ).WithError(err).Error("TAP failed")
                                                return
                                        }
                                        psNew := &PeerState{
@@ -226,7 +332,15 @@ func (s *Server) startUDP() {
                                        s.peersLock.Unlock()
                                        s.peersByIDLock.Unlock()
                                        s.kpLock.Unlock()
-                                       s.logger.WithFields(loopFields).WithFields(fields).WithFields(s.LogFields()).WithFields(peer.LogFields()).Info("Peer initialized")
+                                       s.logger.WithFields(
+                                               loopFields,
+                                       ).WithFields(
+                                               fields,
+                                       ).WithFields(
+                                               s.LogFields(),
+                                       ).WithFields(
+                                               peer.LogFields(),
+                                       ).Info("Peer initialized")
                                }(addr, peer)
                        }
                        udpBufs <- buf
index 2fa90e49f39bb24799b608a349e9ea5cf9fea99b..2f6c5170f7654047c5011790d682c399f3457c37 100644 (file)
@@ -46,7 +46,9 @@ func StatsProcessor(stats string, peers *KnownPeers) {
                "port":    stats,
        }
 
-       logger.WithFields(fields).WithField(
+       logger.WithFields(
+               fields,
+       ).WithField(
                "port", stats,
        ).Debug("Stats are going to listen")
        statsPort, err := net.Listen("tcp", stats)
@@ -65,8 +67,11 @@ func StatsProcessor(stats string, peers *KnownPeers) {
                }
                deadLine := time.Now().Add(rwTimeout)
                if err = conn.SetDeadline(deadLine); err != nil {
-                       logger.WithFields(fields).WithField(
-                               "deadline", deadLine.String(),
+                       logger.WithFields(
+                               fields,
+                       ).WithField(
+                               "deadline",
+                               deadLine.String(),
                        ).WithError(err).Error("Can't set deadline")
                } else if _, err = conn.Read(buf); err != nil {
                        logger.WithFields(fields).WithError(err).Error("Can't read buffer")
@@ -78,7 +83,9 @@ func StatsProcessor(stats string, peers *KnownPeers) {
                                peersList = append(peersList, *peer)
                        }
                        if err = json.NewEncoder(conn).Encode(peersList); err != nil {
-                               logger.WithFields(fields).WithField(
+                               logger.WithFields(
+                                       fields,
+                               ).WithField(
                                        "peers", len(peersList),
                                ).WithError(err).Error("Can't encode to JSON")
                        }