// 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")
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
}
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 {
}
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{}{}
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
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
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
}
}
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
}
}
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 {
/*
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
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")
}
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")
}
}
}()
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)
}
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++
}
- 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.
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(
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)
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()
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()
"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
}
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
}
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")
}
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")
}
}
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")
}
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 {
"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)
}
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{
}
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
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
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)
}
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{}{}
}
"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)
}
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 {
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
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()
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
}
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
}
}
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
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])
"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
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
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
}
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},
_, 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
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()
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{
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{
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
"port": stats,
}
- logger.WithFields(fields).WithField(
+ logger.WithFields(
+ fields,
+ ).WithField(
"port", stats,
).Debug("Stats are going to listen")
statsPort, err := net.Listen("tcp", stats)
}
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")
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")
}