mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-12-27 08:08:46 +01:00
Work on logging format
This commit is contained in:
parent
283e7117cf
commit
ceccd39420
@ -339,7 +339,6 @@ func (device *Device) RemoveAllPeers() {
|
|||||||
defer device.peers.mutex.Unlock()
|
defer device.peers.mutex.Unlock()
|
||||||
|
|
||||||
for key, peer := range device.peers.keyMap {
|
for key, peer := range device.peers.keyMap {
|
||||||
println("rm", peer.String())
|
|
||||||
unsafeRemovePeer(device, peer, key)
|
unsafeRemovePeer(device, peer, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
peer.go
12
peer.go
@ -200,7 +200,8 @@ func (peer *Peer) Start() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
peer.device.log.Debug.Println("Starting:", peer.String())
|
device := peer.device
|
||||||
|
device.log.Debug.Println(peer.String(), ": Starting...")
|
||||||
|
|
||||||
// sanity check : these should be 0
|
// sanity check : these should be 0
|
||||||
|
|
||||||
@ -247,7 +248,7 @@ func (peer *Peer) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
device := peer.device
|
device := peer.device
|
||||||
device.log.Debug.Println("Stopping:", peer.String())
|
device.log.Debug.Println(peer.String(), ": Stopping...")
|
||||||
|
|
||||||
// stop & wait for ongoing peer routines
|
// stop & wait for ongoing peer routines
|
||||||
|
|
||||||
@ -270,6 +271,13 @@ func (peer *Peer) Stop() {
|
|||||||
close(peer.queue.outbound)
|
close(peer.queue.outbound)
|
||||||
close(peer.queue.inbound)
|
close(peer.queue.inbound)
|
||||||
|
|
||||||
|
// close signals
|
||||||
|
|
||||||
|
peer.signal.newKeyPair.Close()
|
||||||
|
peer.signal.handshakeBegin.Close()
|
||||||
|
peer.signal.handshakeCompleted.Close()
|
||||||
|
peer.signal.flushNonceQueue.Close()
|
||||||
|
|
||||||
// clear key pairs
|
// clear key pairs
|
||||||
|
|
||||||
kp := &peer.keyPairs
|
kp := &peer.keyPairs
|
||||||
|
16
receive.go
16
receive.go
@ -430,7 +430,7 @@ func (device *Device) RoutineHandshake() {
|
|||||||
peer.TimerEphemeralKeyCreated()
|
peer.TimerEphemeralKeyCreated()
|
||||||
peer.NewKeyPair()
|
peer.NewKeyPair()
|
||||||
|
|
||||||
logDebug.Println("Creating response message for", peer.String())
|
logDebug.Println(peer.String(), "Creating handshake response")
|
||||||
|
|
||||||
writer := bytes.NewBuffer(temp[:0])
|
writer := bytes.NewBuffer(temp[:0])
|
||||||
binary.Write(writer, binary.LittleEndian, response)
|
binary.Write(writer, binary.LittleEndian, response)
|
||||||
@ -443,7 +443,7 @@ func (device *Device) RoutineHandshake() {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
peer.TimerAnyAuthenticatedPacketTraversal()
|
peer.TimerAnyAuthenticatedPacketTraversal()
|
||||||
} else {
|
} else {
|
||||||
logError.Println("Failed to send response to:", peer.String(), err)
|
logError.Println(peer.String(), "Failed to send handshake response", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case MessageResponseType:
|
case MessageResponseType:
|
||||||
@ -495,14 +495,17 @@ func (device *Device) RoutineHandshake() {
|
|||||||
|
|
||||||
func (peer *Peer) RoutineSequentialReceiver() {
|
func (peer *Peer) RoutineSequentialReceiver() {
|
||||||
|
|
||||||
defer peer.routines.stopping.Done()
|
|
||||||
|
|
||||||
device := peer.device
|
device := peer.device
|
||||||
|
|
||||||
logInfo := device.log.Info
|
logInfo := device.log.Info
|
||||||
logError := device.log.Error
|
logError := device.log.Error
|
||||||
logDebug := device.log.Debug
|
logDebug := device.log.Debug
|
||||||
logDebug.Println("Routine, sequential receiver, started for peer", peer.String())
|
|
||||||
|
func() {
|
||||||
|
defer peer.routines.stopping.Done()
|
||||||
|
logDebug.Println(peer.String(), ": Routine, Sequential Receiver, Stopped")
|
||||||
|
}()
|
||||||
|
|
||||||
|
logDebug.Println(peer.String(), ": Routine, Sequential Receiver, Started")
|
||||||
|
|
||||||
peer.routines.starting.Done()
|
peer.routines.starting.Done()
|
||||||
|
|
||||||
@ -511,7 +514,6 @@ func (peer *Peer) RoutineSequentialReceiver() {
|
|||||||
select {
|
select {
|
||||||
|
|
||||||
case <-peer.routines.stop.Wait():
|
case <-peer.routines.stop.Wait():
|
||||||
logDebug.Println("Routine, sequential receiver, stopped for peer", peer.String())
|
|
||||||
return
|
return
|
||||||
|
|
||||||
case elem := <-peer.queue.inbound:
|
case elem := <-peer.queue.inbound:
|
||||||
|
14
send.go
14
send.go
@ -187,13 +187,16 @@ func (device *Device) RoutineReadFromTUN() {
|
|||||||
func (peer *Peer) RoutineNonce() {
|
func (peer *Peer) RoutineNonce() {
|
||||||
var keyPair *KeyPair
|
var keyPair *KeyPair
|
||||||
|
|
||||||
defer peer.routines.stopping.Done()
|
|
||||||
|
|
||||||
device := peer.device
|
device := peer.device
|
||||||
logDebug := device.log.Debug
|
logDebug := device.log.Debug
|
||||||
logDebug.Println("Routine, nonce worker, started for peer", peer.String())
|
|
||||||
|
defer func() {
|
||||||
|
peer.routines.stopping.Done()
|
||||||
|
logDebug.Println(peer.String(), ": Routine, Nonce Worker, Stopped")
|
||||||
|
}()
|
||||||
|
|
||||||
peer.routines.starting.Done()
|
peer.routines.starting.Done()
|
||||||
|
logDebug.Println(peer.String(), ": Routine, Nonce Worker, Started")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
NextPacket:
|
NextPacket:
|
||||||
@ -215,12 +218,13 @@ func (peer *Peer) RoutineNonce() {
|
|||||||
|
|
||||||
peer.signal.handshakeBegin.Send()
|
peer.signal.handshakeBegin.Send()
|
||||||
|
|
||||||
logDebug.Println("Awaiting key-pair for", peer.String())
|
logDebug.Println(peer.String(), ": Awaiting key-pair")
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-peer.signal.newKeyPair.Wait():
|
case <-peer.signal.newKeyPair.Wait():
|
||||||
|
logDebug.Println(peer.String(), ": Obtained awaited key-pair")
|
||||||
case <-peer.signal.flushNonceQueue.Wait():
|
case <-peer.signal.flushNonceQueue.Wait():
|
||||||
logDebug.Println("Clearing queue for", peer.String())
|
logDebug.Println(peer.String(), ": Flushing nonce queue")
|
||||||
peer.FlushNonceQueue()
|
peer.FlushNonceQueue()
|
||||||
goto NextPacket
|
goto NextPacket
|
||||||
case <-peer.routines.stop.Wait():
|
case <-peer.routines.stop.Wait():
|
||||||
|
@ -11,6 +11,10 @@ func NewSignal() (s Signal) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Signal) Close() {
|
||||||
|
close(s.C)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Signal) Disable() {
|
func (s *Signal) Disable() {
|
||||||
s.enabled.Set(false)
|
s.enabled.Set(false)
|
||||||
s.Clear()
|
s.Clear()
|
||||||
@ -43,7 +47,9 @@ func (s Signal) Clear() {
|
|||||||
/* Unblocks all listeners (forever)
|
/* Unblocks all listeners (forever)
|
||||||
*/
|
*/
|
||||||
func (s Signal) Broadcast() {
|
func (s Signal) Broadcast() {
|
||||||
close(s.C)
|
if s.enabled.Get() {
|
||||||
|
close(s.C)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for the signal
|
/* Wait for the signal
|
||||||
|
6
timer.go
6
timer.go
@ -12,8 +12,7 @@ type Timer struct {
|
|||||||
/* Starts the timer if not already pending
|
/* Starts the timer if not already pending
|
||||||
*/
|
*/
|
||||||
func (t *Timer) Start(dur time.Duration) bool {
|
func (t *Timer) Start(dur time.Duration) bool {
|
||||||
set := t.pending.Swap(true)
|
if !t.pending.Swap(true) {
|
||||||
if !set {
|
|
||||||
t.timer.Reset(dur)
|
t.timer.Reset(dur)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -23,8 +22,7 @@ func (t *Timer) Start(dur time.Duration) bool {
|
|||||||
/* Stops the timer
|
/* Stops the timer
|
||||||
*/
|
*/
|
||||||
func (t *Timer) Stop() {
|
func (t *Timer) Stop() {
|
||||||
set := t.pending.Swap(true)
|
if t.pending.Swap(true) {
|
||||||
if set {
|
|
||||||
t.timer.Stop()
|
t.timer.Stop()
|
||||||
select {
|
select {
|
||||||
case <-t.timer.C:
|
case <-t.timer.C:
|
||||||
|
26
timers.go
26
timers.go
@ -227,14 +227,14 @@ func (peer *Peer) RoutineTimerHandler() {
|
|||||||
|
|
||||||
interval := atomic.LoadUint64(&peer.persistentKeepaliveInterval)
|
interval := atomic.LoadUint64(&peer.persistentKeepaliveInterval)
|
||||||
if interval > 0 {
|
if interval > 0 {
|
||||||
logDebug.Println("Sending keep-alive to", peer.String())
|
logDebug.Println(peer.String(), ": Send keep-alive (persistent)")
|
||||||
peer.timer.keepalivePassive.Stop()
|
peer.timer.keepalivePassive.Stop()
|
||||||
peer.SendKeepAlive()
|
peer.SendKeepAlive()
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-peer.timer.keepalivePassive.Wait():
|
case <-peer.timer.keepalivePassive.Wait():
|
||||||
|
|
||||||
logDebug.Println("Sending keep-alive to", peer.String())
|
logDebug.Println(peer.String(), ": Send keep-alive (passive)")
|
||||||
|
|
||||||
peer.SendKeepAlive()
|
peer.SendKeepAlive()
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ func (peer *Peer) RoutineTimerHandler() {
|
|||||||
|
|
||||||
case <-peer.timer.zeroAllKeys.Wait():
|
case <-peer.timer.zeroAllKeys.Wait():
|
||||||
|
|
||||||
logDebug.Println("Clearing all key material for", peer.String())
|
logDebug.Println(peer.String(), ": Clear all key-material (timer event)")
|
||||||
|
|
||||||
hs := &peer.handshake
|
hs := &peer.handshake
|
||||||
hs.mutex.Lock()
|
hs.mutex.Lock()
|
||||||
@ -280,7 +280,7 @@ func (peer *Peer) RoutineTimerHandler() {
|
|||||||
// handshake timers
|
// handshake timers
|
||||||
|
|
||||||
case <-peer.timer.handshakeNew.Wait():
|
case <-peer.timer.handshakeNew.Wait():
|
||||||
logInfo.Println("Retrying handshake with", peer.String())
|
logInfo.Println(peer.String(), ": Retrying handshake (timer event)")
|
||||||
peer.signal.handshakeBegin.Send()
|
peer.signal.handshakeBegin.Send()
|
||||||
|
|
||||||
case <-peer.timer.handshakeTimeout.Wait():
|
case <-peer.timer.handshakeTimeout.Wait():
|
||||||
@ -296,17 +296,18 @@ func (peer *Peer) RoutineTimerHandler() {
|
|||||||
// send new handshake
|
// send new handshake
|
||||||
|
|
||||||
err := peer.sendNewHandshake()
|
err := peer.sendNewHandshake()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logInfo.Println(
|
logInfo.Println(peer.String(), ": Failed to send handshake initiation", err)
|
||||||
"Failed to send handshake to peer:", peer.String(), "(", err, ")")
|
} else {
|
||||||
|
logDebug.Println(peer.String(), ": Send handshake initiation (subsequent)")
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-peer.timer.handshakeDeadline.Wait():
|
case <-peer.timer.handshakeDeadline.Wait():
|
||||||
|
|
||||||
// clear all queued packets and stop keep-alive
|
// clear all queued packets and stop keep-alive
|
||||||
|
|
||||||
logInfo.Println(
|
logInfo.Println(peer.String(), ": Handshake negotiation timed-out")
|
||||||
"Handshake negotiation timed out for:", peer.String())
|
|
||||||
|
|
||||||
peer.signal.flushNonceQueue.Send()
|
peer.signal.flushNonceQueue.Send()
|
||||||
peer.timer.keepalivePersistent.Stop()
|
peer.timer.keepalivePersistent.Stop()
|
||||||
@ -319,17 +320,18 @@ func (peer *Peer) RoutineTimerHandler() {
|
|||||||
peer.signal.handshakeBegin.Disable()
|
peer.signal.handshakeBegin.Disable()
|
||||||
|
|
||||||
err := peer.sendNewHandshake()
|
err := peer.sendNewHandshake()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logInfo.Println(
|
logInfo.Println(peer.String(), ": Failed to send handshake initiation", err)
|
||||||
"Failed to send handshake to peer:", peer.String(), "(", err, ")")
|
} else {
|
||||||
|
logDebug.Println(peer.String(), ": Send handshake initiation (initial)")
|
||||||
}
|
}
|
||||||
|
|
||||||
peer.timer.handshakeDeadline.Reset(RekeyAttemptTime)
|
peer.timer.handshakeDeadline.Reset(RekeyAttemptTime)
|
||||||
|
|
||||||
case <-peer.signal.handshakeCompleted.Wait():
|
case <-peer.signal.handshakeCompleted.Wait():
|
||||||
|
|
||||||
logInfo.Println(
|
logInfo.Println(peer.String(), ": Handshake completed")
|
||||||
"Handshake completed for:", peer.String())
|
|
||||||
|
|
||||||
atomic.StoreInt64(
|
atomic.StoreInt64(
|
||||||
&peer.stats.lastHandshakeNano,
|
&peer.stats.lastHandshakeNano,
|
||||||
|
Loading…
Reference in New Issue
Block a user