add logging, write vscode config to run debugger
This commit is contained in:
parent
a28a84eafb
commit
4a2f315b7c
6 changed files with 38 additions and 3 deletions
19
.vscode/launch.json
vendored
Normal file
19
.vscode/launch.json
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Debug",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "debug",
|
||||||
|
"program": "${workspaceFolder}",
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Debug this test",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "test"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
1
go.mod
1
go.mod
|
|
@ -4,5 +4,6 @@ go 1.23.4
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -1,4 +1,6 @@
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88=
|
||||||
|
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
||||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
|
|
|
||||||
5
net/lux_log.go
Normal file
5
net/lux_log.go
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
package net
|
||||||
|
|
||||||
|
import "github.com/op/go-logging"
|
||||||
|
|
||||||
|
var log = logging.MustGetLogger("net")
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"lux/crypto"
|
"lux/crypto"
|
||||||
"lux/proto"
|
"lux/proto"
|
||||||
"net"
|
"net"
|
||||||
|
|
@ -93,9 +92,8 @@ func EncryptLuxPacket(packet LuxPacket, key crypto.LuxKey, target *net.UDPAddr)
|
||||||
var paddingLen int
|
var paddingLen int
|
||||||
packetLen := LUX_PROTO_PACKET_HDRLEN + packet.Buffer.Length()
|
packetLen := LUX_PROTO_PACKET_HDRLEN + packet.Buffer.Length()
|
||||||
if packetLen%encrypter.BlockSize() != 0 {
|
if packetLen%encrypter.BlockSize() != 0 {
|
||||||
//paddingLen = ((packetLen / encrypter.BlockSize()) + 1) * encrypter.BlockSize()
|
|
||||||
paddingLen = encrypter.BlockSize() - (packetLen % encrypter.BlockSize())
|
paddingLen = encrypter.BlockSize() - (packetLen % encrypter.BlockSize())
|
||||||
log.Default().Print(packetLen, paddingLen)
|
log.Debugf("packetLen %d paddingLen %d\n", packetLen, paddingLen)
|
||||||
} else {
|
} else {
|
||||||
paddingLen = 0
|
paddingLen = 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -214,12 +214,16 @@ func (r *LuxRouter) Recv() (LuxPacket, error) {
|
||||||
packet, err = DecryptLuxPacket(dgram, route.Key)
|
packet, err = DecryptLuxPacket(dgram, route.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// do we really fail here?
|
// do we really fail here?
|
||||||
|
log.Debugf("DecryptLuxPacket err %v for route %v", err, route)
|
||||||
return packet, err
|
return packet, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if LuxID matches
|
// check if LuxID matches
|
||||||
if !bytes.Equal(packet.Target.UUID[:], route.Key.Id.UUID[:]) {
|
if !bytes.Equal(packet.Target.UUID[:], route.Key.Id.UUID[:]) {
|
||||||
// not matches.. we discard route and throw away packet
|
// not matches.. we discard route and throw away packet
|
||||||
|
log.Infof("packet from %s received at route %v mismatches associated target UUID %s",
|
||||||
|
dgram.Target.String(), route, route.Key.Id.String())
|
||||||
|
|
||||||
r.DeleteRoute(route)
|
r.DeleteRoute(route)
|
||||||
return packet, errors.New("bogus packet from established route")
|
return packet, errors.New("bogus packet from established route")
|
||||||
/* NOTE:
|
/* NOTE:
|
||||||
|
|
@ -246,6 +250,9 @@ func (r *LuxRouter) Recv() (LuxPacket, error) {
|
||||||
var ok bool
|
var ok bool
|
||||||
var route *LuxRoute
|
var route *LuxRoute
|
||||||
if route, ok = r.routes[packet.Target]; ok {
|
if route, ok = r.routes[packet.Target]; ok {
|
||||||
|
log.Debugf("updating route %s: %s -> %s", route.Key.Id.String,
|
||||||
|
route.Destination.String(), dgram.Target.String())
|
||||||
|
|
||||||
route.Destination = dgram.Target
|
route.Destination = dgram.Target
|
||||||
route.Associated = dgram.Channel
|
route.Associated = dgram.Channel
|
||||||
// since packet arrived from different transport, we flush nonces
|
// since packet arrived from different transport, we flush nonces
|
||||||
|
|
@ -258,11 +265,14 @@ func (r *LuxRouter) Recv() (LuxPacket, error) {
|
||||||
Nonces: NewLuxNonceList(),
|
Nonces: NewLuxNonceList(),
|
||||||
}
|
}
|
||||||
route = r.routes[key.Id]
|
route = r.routes[key.Id]
|
||||||
|
|
||||||
|
log.Debugf("established route %s <-> %s", route.Key.Id.String(), route.Destination.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate nonce
|
// rotate nonce
|
||||||
if !route.Nonces.RotateOrFail(packet.Nonce) {
|
if !route.Nonces.RotateOrFail(packet.Nonce) {
|
||||||
// failed nonce, discard packet
|
// failed nonce, discard packet
|
||||||
|
log.Debug("failed nonce")
|
||||||
return packet, fmt.Errorf("packet failed nonce check")
|
return packet, fmt.Errorf("packet failed nonce check")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue