diff --git a/pkg/client/client.go b/pkg/client/client.go index 9f028a32..90580791 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -17,15 +17,15 @@ import ( "github.com/Indra-Labs/indra/pkg/types" "github.com/Indra-Labs/indra/pkg/wire" "github.com/Indra-Labs/indra/pkg/wire/cipher" - "github.com/Indra-Labs/indra/pkg/wire/confirmation" + "github.com/Indra-Labs/indra/pkg/wire/confirm" "github.com/Indra-Labs/indra/pkg/wire/delay" "github.com/Indra-Labs/indra/pkg/wire/exit" "github.com/Indra-Labs/indra/pkg/wire/forward" "github.com/Indra-Labs/indra/pkg/wire/layer" "github.com/Indra-Labs/indra/pkg/wire/noop" "github.com/Indra-Labs/indra/pkg/wire/purchase" - "github.com/Indra-Labs/indra/pkg/wire/reply" "github.com/Indra-Labs/indra/pkg/wire/response" + "github.com/Indra-Labs/indra/pkg/wire/reverse" "github.com/Indra-Labs/indra/pkg/wire/session" "github.com/Indra-Labs/indra/pkg/wire/token" log2 "github.com/cybriq/proc/pkg/log" @@ -69,66 +69,66 @@ func New(tpt ifc.Transport, hdrPrv *prv.Key, no *node.Node, } // Start a single thread of the Client. -func (c *Client) Start() { +func (cl *Client) Start() { out: for { - if c.runner() { + if cl.runner() { break out } } } -func (c *Client) runner() (out bool) { +func (cl *Client) runner() (out bool) { select { - case <-c.C.Wait(): - c.Cleanup() + case <-cl.C.Wait(): + cl.Cleanup() out = true break - case b := <-c.Node.Receive(): + case b := <-cl.Node.Receive(): // process received message var onion types.Onion var e error - cur := slice.NewCursor() - if onion, e = wire.PeelOnion(b, cur); check(e) { + c := slice.NewCursor() + if onion, e = wire.PeelOnion(b, c); check(e) { break } switch on := onion.(type) { case *cipher.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.cipher(on, b, cur) - case *confirmation.OnionSkin: + cl.cipher(on, b, c) + case *confirm.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.confirmation(on, b, cur) + cl.confirm(on, b, c) case *delay.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.delay(on, b, cur) + cl.delay(on, b, c) case *exit.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.exit(on, b, cur) + cl.exit(on, b, c) case *forward.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.forward(on, b, cur) + cl.forward(on, b, c) case *layer.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.layer(on, b, cur) + cl.layer(on, b, c) case *noop.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.noop(on, b, cur) + cl.noop(on, b, c) case *purchase.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.purchase(on, b, cur) - case *reply.OnionSkin: + cl.purchase(on, b, c) + case *reverse.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.reply(on, b, cur) + cl.reply(on, b, c) case *response.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.response(on, b, cur) + cl.response(on, b, c) case *session.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.session(on, b, cur) + cl.session(on, b, c) case *token.OnionSkin: log.I.Ln(reflect.TypeOf(on)) - c.token(on, b, cur) + cl.token(on, b, c) default: log.I.S("unrecognised packet", b) } @@ -136,91 +136,93 @@ func (c *Client) runner() (out bool) { return false } -func (c *Client) cipher(on *cipher.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) cipher(on *cipher.OnionSkin, b slice.Bytes, cur *slice.Cursor) { // This either is in a forward only SendKeys message or we are the buyer // and these are our session keys. } -func (c *Client) confirmation(on *confirmation.OnionSkin, b slice.Bytes, - cur *slice.Cursor) { +func (cl *Client) confirm(on *confirm.OnionSkin, b slice.Bytes, + c *slice.Cursor) { // This will be an 8 byte nonce that confirms a message passed, ping and // cipher onions return these, as they are pure forward messages that // send a message one way and the confirmation is the acknowledgement. log.I.S(on) } -func (c *Client) delay(on *delay.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) delay(on *delay.OnionSkin, b slice.Bytes, cur *slice.Cursor) { // this is a message to hold the message in the buffer until a duration // elapses. The accounting for the remainder of the message adds a // factor to the effective byte consumption in accordance with the time // to be stored. } -func (c *Client) exit(on *exit.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) exit(on *exit.OnionSkin, b slice.Bytes, cur *slice.Cursor) { // payload is forwarded to a local port and the response is forwarded // back with a reply header. } -func (c *Client) forward(on *forward.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) forward(on *forward.OnionSkin, b slice.Bytes, c *slice.Cursor) { // forward the whole buffer received onwards. Usually there will be a // layer.OnionSkin under this which will be unwrapped by the receiver. - if on.AddrPort.String() == c.Node.AddrPort.String() { + if on.AddrPort.String() == cl.Node.AddrPort.String() { // it is for us, we want to unwrap the next // part. - log.I.Ln("processing new message") - c.Node.Send(b[*cur:]) + log.I.Ln("processing new message", *c) + b = append(b[*c:], slice.NoisePad(int(*c))...) + cl.Node.Send(b) } else { // we need to forward this message onion. log.I.Ln("forwarding") - c.Send(on.AddrPort, b) + cl.Send(on.AddrPort, b) } } -func (c *Client) layer(on *layer.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) layer(on *layer.OnionSkin, b slice.Bytes, c *slice.Cursor) { // this is probably an encrypted layer for us. log.I.Ln("decrypting onion skin") - // log.I.S(on, b[*cur:].ToBytes()) - rcv := c.ReceiveCache.FindCloaked(on.Cloak) + // log.I.S(on, b[*c:].ToBytes()) + rcv := cl.ReceiveCache.FindCloaked(on.Cloak) if rcv == nil { log.I.Ln("no matching key found from cloaked key") return } - on.Decrypt(rcv.Key, b, cur) - log.I.S(b[*cur:].ToBytes()) - c.Node.Send(b[*cur:]) + on.Decrypt(rcv.Key, b, c) + b = append(b[*c:], slice.NoisePad(int(*c))...) + log.I.S(b.ToBytes()) + cl.Node.Send(b) } -func (c *Client) noop(on *noop.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) noop(on *noop.OnionSkin, b slice.Bytes, c *slice.Cursor) { // this won't happen normally } -func (c *Client) purchase(on *purchase.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) purchase(on *purchase.OnionSkin, b slice.Bytes, c *slice.Cursor) { // Create a new Session. s := &Session{} - c.Mutex.Lock() + cl.Mutex.Lock() s.Deadline = time.Now().Add(DefaultDeadline) - c.Sessions = append(c.Sessions, s) - c.Mutex.Unlock() + cl.Sessions = append(cl.Sessions, s) + cl.Mutex.Unlock() } -func (c *Client) reply(on *reply.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) reply(on *reverse.OnionSkin, b slice.Bytes, c *slice.Cursor) { // Reply means another OnionSkin is coming and the payload encryption // uses the Payload key. - if on.AddrPort.String() == c.Node.AddrPort.String() { + if on.AddrPort.String() == cl.Node.AddrPort.String() { // it is for us, we want to unwrap the next part. - c.Node.Send(b) + cl.Node.Send(b) } else { // we need to forward this message onion. - c.Send(on.AddrPort, b) + cl.Send(on.AddrPort, b) } } -func (c *Client) response(on *response.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) response(on *response.OnionSkin, b slice.Bytes, cur *slice.Cursor) { // Response is a payload from an exit message. } -func (c *Client) session(s *session.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) session(s *session.OnionSkin, b slice.Bytes, cur *slice.Cursor) { // Session is returned from a Purchase message in the reply layers. // // Session has a nonce.ID that is given in the last layer of a LN sphinx @@ -229,26 +231,26 @@ func (c *Client) session(s *session.OnionSkin, b slice.Bytes, cur *slice.Cursor) // nonce, so long as it has not yet expired. } -func (c *Client) token(t *token.OnionSkin, b slice.Bytes, cur *slice.Cursor) { +func (cl *Client) token(t *token.OnionSkin, b slice.Bytes, cur *slice.Cursor) { // not really sure if we are using these. return } -func (c *Client) Cleanup() { +func (cl *Client) Cleanup() { // Do cleanup stuff before shutdown. } -func (c *Client) Shutdown() { - c.C.Q() +func (cl *Client) Shutdown() { + cl.C.Q() } -func (c *Client) Send(addr *netip.AddrPort, b slice.Bytes) { +func (cl *Client) Send(addr *netip.AddrPort, b slice.Bytes) { // first search if we already have the node available with connection // open. as := addr.String() - for i := range c.Nodes { - if as == c.Nodes[i].Addr { - c.Nodes[i].Transport.Send(b) + for i := range cl.Nodes { + if as == cl.Nodes[i].Addr { + cl.Nodes[i].Transport.Send(b) return } } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 65f901f5..1f1a471a 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -38,7 +38,6 @@ func TestPing(t *testing.T) { } pldPub := pub.Derive(pldPrv) addr := slice.GenerateRandomAddrPortIPv4() - log.I.S(addr) nodes[i], _ = node.New(addr, hdrPub, pldPub, hdrPrv, pldPrv, transports[i]) if clients[i], e = New(transports[i], hdrPrv, nodes[i], nil); check(e) { t.Error(e) diff --git a/pkg/wire/cipher/cipher.go b/pkg/wire/cipher/cipher.go index 123f0007..22cebd91 100644 --- a/pkg/wire/cipher/cipher.go +++ b/pkg/wire/cipher/cipher.go @@ -23,10 +23,6 @@ var ( // // After ~10 seconds these can be purged from the cache as they are otherwise a // DoS vector buffer flooding. -// -// The Decode function wipes the original message data for security as the -// private keys inside it are no longer needed and any secret should only have -// one storage, so it doesn't appear in any GC later. type OnionSkin struct { Header, Payload *pub.Key types.Onion diff --git a/pkg/wire/codec.go b/pkg/wire/codec.go index b0f04240..047e5d6e 100644 --- a/pkg/wire/codec.go +++ b/pkg/wire/codec.go @@ -7,15 +7,15 @@ import ( "github.com/Indra-Labs/indra/pkg/slice" "github.com/Indra-Labs/indra/pkg/types" "github.com/Indra-Labs/indra/pkg/wire/cipher" - "github.com/Indra-Labs/indra/pkg/wire/confirmation" + "github.com/Indra-Labs/indra/pkg/wire/confirm" "github.com/Indra-Labs/indra/pkg/wire/delay" "github.com/Indra-Labs/indra/pkg/wire/exit" "github.com/Indra-Labs/indra/pkg/wire/forward" "github.com/Indra-Labs/indra/pkg/wire/layer" "github.com/Indra-Labs/indra/pkg/wire/magicbytes" "github.com/Indra-Labs/indra/pkg/wire/purchase" - "github.com/Indra-Labs/indra/pkg/wire/reply" "github.com/Indra-Labs/indra/pkg/wire/response" + "github.com/Indra-Labs/indra/pkg/wire/reverse" "github.com/Indra-Labs/indra/pkg/wire/session" "github.com/Indra-Labs/indra/pkg/wire/token" log2 "github.com/cybriq/proc/pkg/log" @@ -42,8 +42,8 @@ func PeelOnion(b slice.Bytes, c *slice.Cursor) (on types.Onion, e error) { return } on = o - case confirmation.MagicString: - o := &confirmation.OnionSkin{} + case confirm.MagicString: + o := &confirm.OnionSkin{} if e = o.Decode(b, c); check(e) { return } @@ -78,8 +78,8 @@ func PeelOnion(b slice.Bytes, c *slice.Cursor) (on types.Onion, e error) { return } on = o - case reply.MagicString: - o := &reply.OnionSkin{} + case reverse.MagicString: + o := &reverse.OnionSkin{} if e = o.Decode(b, c); check(e) { return } diff --git a/pkg/wire/codec_test.go b/pkg/wire/codec_test.go index 660912dd..973e37b5 100644 --- a/pkg/wire/codec_test.go +++ b/pkg/wire/codec_test.go @@ -17,14 +17,14 @@ import ( "github.com/Indra-Labs/indra/pkg/testutils" "github.com/Indra-Labs/indra/pkg/types" "github.com/Indra-Labs/indra/pkg/wire/cipher" - "github.com/Indra-Labs/indra/pkg/wire/confirmation" + "github.com/Indra-Labs/indra/pkg/wire/confirm" "github.com/Indra-Labs/indra/pkg/wire/delay" "github.com/Indra-Labs/indra/pkg/wire/exit" "github.com/Indra-Labs/indra/pkg/wire/forward" "github.com/Indra-Labs/indra/pkg/wire/layer" "github.com/Indra-Labs/indra/pkg/wire/purchase" - "github.com/Indra-Labs/indra/pkg/wire/reply" "github.com/Indra-Labs/indra/pkg/wire/response" + "github.com/Indra-Labs/indra/pkg/wire/reverse" "github.com/Indra-Labs/indra/pkg/wire/session" "github.com/Indra-Labs/indra/pkg/wire/token" log2 "github.com/cybriq/proc/pkg/log" @@ -73,9 +73,9 @@ func TestOnionSkins_Confirmation(t *testing.T) { if oncn, e = PeelOnion(onb, c); check(e) { t.FailNow() } - var cf *confirmation.OnionSkin + var cf *confirm.OnionSkin var ok bool - if cf, ok = oncn.(*confirmation.OnionSkin); !ok { + if cf, ok = oncn.(*confirm.OnionSkin); !ok { t.Error("did not unwrap expected type") t.FailNow() } @@ -226,8 +226,8 @@ func TestOnionSkins_Layer(t *testing.T) { t.Error(e) t.FailNow() } - oc := &confirmation.OnionSkin{} - if oc, ok = onc.(*confirmation.OnionSkin); !ok { + oc := &confirm.OnionSkin{} + if oc, ok = onc.(*confirm.OnionSkin); !ok { t.Error("did not unwrap expected type") t.FailNow() } @@ -300,8 +300,8 @@ func TestOnionSkins_Reply(t *testing.T) { if onf, e = PeelOnion(onb, c); check(e) { t.FailNow() } - var cf *reply.OnionSkin - if cf, ok = onf.(*reply.OnionSkin); !ok { + var cf *reverse.OnionSkin + if cf, ok = onf.(*reverse.OnionSkin); !ok { t.Error("did not unwrap expected type", reflect.TypeOf(onf)) t.FailNow() } diff --git a/pkg/wire/confirmation/confirmation.go b/pkg/wire/confirm/confirmation.go similarity index 98% rename from pkg/wire/confirmation/confirmation.go rename to pkg/wire/confirm/confirmation.go index bc0edb57..cd34cd1d 100644 --- a/pkg/wire/confirmation/confirmation.go +++ b/pkg/wire/confirm/confirmation.go @@ -1,4 +1,4 @@ -package confirmation +package confirm import ( "fmt" diff --git a/pkg/wire/layers.go b/pkg/wire/layers.go index b8b34d63..639cc5cc 100644 --- a/pkg/wire/layers.go +++ b/pkg/wire/layers.go @@ -13,15 +13,15 @@ import ( "github.com/Indra-Labs/indra/pkg/slice" "github.com/Indra-Labs/indra/pkg/types" "github.com/Indra-Labs/indra/pkg/wire/cipher" - "github.com/Indra-Labs/indra/pkg/wire/confirmation" + "github.com/Indra-Labs/indra/pkg/wire/confirm" "github.com/Indra-Labs/indra/pkg/wire/delay" "github.com/Indra-Labs/indra/pkg/wire/exit" "github.com/Indra-Labs/indra/pkg/wire/forward" "github.com/Indra-Labs/indra/pkg/wire/layer" "github.com/Indra-Labs/indra/pkg/wire/noop" "github.com/Indra-Labs/indra/pkg/wire/purchase" - "github.com/Indra-Labs/indra/pkg/wire/reply" "github.com/Indra-Labs/indra/pkg/wire/response" + "github.com/Indra-Labs/indra/pkg/wire/reverse" "github.com/Indra-Labs/indra/pkg/wire/session" "github.com/Indra-Labs/indra/pkg/wire/token" ) @@ -46,7 +46,7 @@ func (o OnionSkins) Cipher(hdr, pld *pub.Key) OnionSkins { } func (o OnionSkins) Confirmation(id nonce.ID) OnionSkins { - return append(o, &confirmation.OnionSkin{ID: id}) + return append(o, &confirm.OnionSkin{ID: id}) } func (o OnionSkins) Delay(d time.Duration) OnionSkins { @@ -86,7 +86,7 @@ func (o OnionSkins) Purchase(nBytes uint64, prvs [3]*prv.Key, }) } func (o OnionSkins) Reply(ip *netip.AddrPort) OnionSkins { - return append(o, &reply.OnionSkin{AddrPort: ip, Onion: os}) + return append(o, &reverse.OnionSkin{AddrPort: ip, Onion: os}) } func (o OnionSkins) Response(res slice.Bytes) OnionSkins { rs := response.OnionSkin(res) diff --git a/pkg/wire/onion_test.go b/pkg/wire/onion_test.go index ba36434f..215187a3 100644 --- a/pkg/wire/onion_test.go +++ b/pkg/wire/onion_test.go @@ -14,12 +14,12 @@ import ( "github.com/Indra-Labs/indra/pkg/testutils" "github.com/Indra-Labs/indra/pkg/types" "github.com/Indra-Labs/indra/pkg/wire/cipher" - "github.com/Indra-Labs/indra/pkg/wire/confirmation" + "github.com/Indra-Labs/indra/pkg/wire/confirm" "github.com/Indra-Labs/indra/pkg/wire/exit" "github.com/Indra-Labs/indra/pkg/wire/forward" "github.com/Indra-Labs/indra/pkg/wire/layer" "github.com/Indra-Labs/indra/pkg/wire/purchase" - "github.com/Indra-Labs/indra/pkg/wire/reply" + "github.com/Indra-Labs/indra/pkg/wire/reverse" log2 "github.com/cybriq/proc/pkg/log" ) @@ -54,7 +54,7 @@ func PeelOnionSkin(t *testing.T, b slice.Bytes, } func PeelConfirmation(t *testing.T, b slice.Bytes, - c *slice.Cursor) (cn *confirmation.OnionSkin) { + c *slice.Cursor) (cn *confirm.OnionSkin) { var ok bool var e error @@ -62,7 +62,7 @@ func PeelConfirmation(t *testing.T, b slice.Bytes, if on, e = PeelOnion(b, c); check(e) { t.Error(e) } - if cn, ok = on.(*confirmation.OnionSkin); !ok { + if cn, ok = on.(*confirm.OnionSkin); !ok { t.Error("did not unwrap expected type", reflect.TypeOf(on)) } return @@ -84,7 +84,7 @@ func PeelPurchase(t *testing.T, b slice.Bytes, } func PeelReply(t *testing.T, b slice.Bytes, - c *slice.Cursor) (rp *reply.OnionSkin) { + c *slice.Cursor) (rp *reverse.OnionSkin) { var ok bool var e error @@ -92,7 +92,7 @@ func PeelReply(t *testing.T, b slice.Bytes, if on, e = PeelOnion(b, c); check(e) { t.Error(e) } - if rp, ok = on.(*reply.OnionSkin); !ok { + if rp, ok = on.(*reverse.OnionSkin); !ok { t.Error("did not unwrap expected type", reflect.TypeOf(on)) } return diff --git a/pkg/wire/reply/reply.go b/pkg/wire/reverse/reply.go similarity index 99% rename from pkg/wire/reply/reply.go rename to pkg/wire/reverse/reply.go index 02964c88..a5e07bd5 100644 --- a/pkg/wire/reply/reply.go +++ b/pkg/wire/reverse/reply.go @@ -1,4 +1,4 @@ -package reply +package reverse import ( "net" diff --git a/version.go b/version.go index 794c196d..272bbcbe 100644 --- a/version.go +++ b/version.go @@ -10,11 +10,11 @@ var ( // GitRef is the gitref, as in refs/heads/branchname. GitRef = "refs/heads/main" // ParentGitCommit is the commit hash of the parent HEAD. - ParentGitCommit = "090ea9584cb7987911cccd390e5470e966938378" + ParentGitCommit = "ed542f0b9ced648125640f1f8c4f5f4fe55cd677" // BuildTime stores the time when the current binary was built. - BuildTime = "2022-12-29T08:07:49Z" - // SemVer lists the (latest) git tag on the build. - SemVer = "v0.0.256" + BuildTime = "2022-12-29T09:14:38Z" + // SemVer lists the (latest) git tag on the release. + SemVer = "v0.0.257" // PathBase is the path base returned from runtime caller. PathBase = "/home/loki/src/github.com/Indra-Labs/indra/" // Major is the major number from the tag. @@ -22,7 +22,7 @@ var ( // Minor is the minor number from the tag. Minor = 0 // Patch is the patch version number from the tag. - Patch = 256 + Patch = 257 ) // Version returns a pretty printed version information string.