rename to indra.Engine

This commit is contained in:
херетик
2023-01-28 11:13:23 +00:00
parent 7cbd2e12cd
commit b042df3fa2
25 changed files with 90 additions and 75 deletions

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"sync"

View File

@@ -1,10 +1,12 @@
package client
package indra
import (
"sync"
"time"
"github.com/cybriq/qu"
"go.uber.org/atomic"
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/pkg/crypto/key/prv"
"github.com/indra-labs/indra/pkg/crypto/key/pub"
@@ -15,7 +17,6 @@ import (
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/traffic"
"github.com/indra-labs/indra/pkg/types"
"go.uber.org/atomic"
)
var (
@@ -23,7 +24,7 @@ var (
check = log.E.Chk
)
type Client struct {
type Engine struct {
*node.Node
node.Nodes
sync.Mutex
@@ -36,7 +37,7 @@ type Client struct {
}
func NewClient(tpt types.Transport, hdrPrv *prv.Key, no *node.Node,
nodes node.Nodes) (c *Client, e error) {
nodes node.Nodes) (c *Engine, e error) {
no.Transport = tpt
no.IdentityPrv = hdrPrv
@@ -47,7 +48,7 @@ func NewClient(tpt types.Transport, hdrPrv *prv.Key, no *node.Node,
}
// Add our first return session.
no.AddSession(traffic.NewSession(nonce.NewID(), no.Peer, 0, nil, nil, 5))
c = &Client{
c = &Engine{
Confirms: confirm.NewConfirms(),
Node: no,
Nodes: nodes,
@@ -57,8 +58,8 @@ func NewClient(tpt types.Transport, hdrPrv *prv.Key, no *node.Node,
return
}
// Start a single thread of the Client.
func (cl *Client) Start() {
// Start a single thread of the Engine.
func (cl *Engine) Start() {
for {
if cl.handler() {
break
@@ -66,7 +67,7 @@ func (cl *Client) Start() {
}
}
func (cl *Client) RegisterConfirmation(hook confirm.Hook,
func (cl *Engine) RegisterConfirmation(hook confirm.Hook,
cnf nonce.ID) {
if hook == nil {
@@ -81,13 +82,13 @@ func (cl *Client) RegisterConfirmation(hook confirm.Hook,
// Cleanup closes and flushes any resources the client opened that require sync
// in order to reopen correctly.
func (cl *Client) Cleanup() {
func (cl *Engine) Cleanup() {
// Do cleanup stuff before shutdown.
}
// Shutdown triggers the shutdown of the client and the Cleanup before
// finishing.
func (cl *Client) Shutdown() {
func (cl *Engine) Shutdown() {
if cl.ShuttingDown.Load() {
return
}

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"os"
@@ -7,6 +7,8 @@ import (
"time"
"github.com/cybriq/qu"
"go.uber.org/atomic"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/crypto/sha256"
log2 "github.com/indra-labs/indra/pkg/proc/log"
@@ -15,12 +17,11 @@ import (
"github.com/indra-labs/indra/pkg/transport"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/indra/pkg/util/tests"
"go.uber.org/atomic"
)
func TestClient_SendKeys(t *testing.T) {
log2.SetLogLevel(log2.Trace)
var clients []*Client
var clients []*Engine
var e error
if clients, e = CreateNMockCircuits(false, 2); check(e) {
t.Error(e)
@@ -66,7 +67,7 @@ func TestClient_SendKeys(t *testing.T) {
func TestClient_SendPing(t *testing.T) {
log2.SetLogLevel(log2.Debug)
var clients []*Client
var clients []*Engine
var e error
if clients, e = CreateNMockCircuits(true, 2); check(e) {
t.Error(e)
@@ -113,7 +114,7 @@ out:
func TestClient_SendExit(t *testing.T) {
log2.SetLogLevel(log2.Debug)
var clients []*Client
var clients []*Engine
var e error
if clients, e = CreateNMockCircuits(true, 2); check(e) {
t.Error(e)
@@ -193,7 +194,7 @@ out:
func TestClient_SendGetBalance(t *testing.T) {
log2.SetLogLevel(log2.Debug)
var clients []*Client
var clients []*Engine
var e error
if clients, e = CreateNMockCircuits(true, 2); check(e) {
t.Error(e)

View File

@@ -1,15 +1,16 @@
package client
package indra
import (
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/onion/layers/balance"
"github.com/indra-labs/indra/pkg/traffic"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/lnd/lnd/lnwire"
)
func (cl *Client) balance(on *balance.Layer,
func (cl *Engine) balance(on *balance.Layer,
b slice.Bytes, c *slice.Cursor, prev types.Onion) {
log.T.S(on.ConfID)

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"github.com/indra-labs/indra/pkg/onion/layers/confirm"
@@ -6,7 +6,7 @@ import (
"github.com/indra-labs/indra/pkg/util/slice"
)
func (cl *Client) confirm(on *confirm.Layer,
func (cl *Engine) confirm(on *confirm.Layer,
b slice.Bytes, c *slice.Cursor, prev types.Onion) {
// When a confirm arrives check if it is registered for and run

View File

@@ -1,6 +1,8 @@
package client
package indra
import (
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/crypto/key/pub"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/onion"
@@ -11,10 +13,9 @@ import (
"github.com/indra-labs/indra/pkg/onion/layers/session"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/lnd/lnd/lnwire"
)
func (cl *Client) crypt(on *crypt.Layer, b slice.Bytes,
func (cl *Engine) crypt(on *crypt.Layer, b slice.Bytes,
c *slice.Cursor, prev types.Onion) {
// this is probably an encrypted crypt for us.

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"time"
@@ -8,7 +8,7 @@ import (
"github.com/indra-labs/indra/pkg/util/slice"
)
func (cl *Client) delay(on *delay.Layer, b slice.Bytes,
func (cl *Engine) delay(on *delay.Layer, b slice.Bytes,
c *slice.Cursor, prev types.Onion) {
// this is a message to hold the message in the buffer until a duration

View File

@@ -1,8 +1,10 @@
package client
package indra
import (
"time"
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/onion"
"github.com/indra-labs/indra/pkg/onion/layers/crypt"
@@ -10,10 +12,9 @@ import (
"github.com/indra-labs/indra/pkg/onion/layers/response"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/lnd/lnd/lnwire"
)
func (cl *Client) exit(ex *exit.Layer, b slice.Bytes,
func (cl *Engine) exit(ex *exit.Layer, b slice.Bytes,
c *slice.Cursor, prev types.Onion) {
// payload is forwarded to a local port and the result is forwarded

View File

@@ -1,14 +1,15 @@
package client
package indra
import (
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/onion/layers/crypt"
"github.com/indra-labs/indra/pkg/onion/layers/forward"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/lnd/lnd/lnwire"
)
func (cl *Client) forward(on *forward.Layer, b slice.Bytes,
func (cl *Engine) forward(on *forward.Layer, b slice.Bytes,
c *slice.Cursor, prev types.Onion) {
// forward the whole buffer received onwards. Usually there will be a

View File

@@ -1,8 +1,10 @@
package client
package indra
import (
"fmt"
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/onion"
"github.com/indra-labs/indra/pkg/onion/layers/balance"
"github.com/indra-labs/indra/pkg/onion/layers/crypt"
@@ -10,10 +12,9 @@ import (
"github.com/indra-labs/indra/pkg/traffic"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/lnd/lnd/lnwire"
)
func (cl *Client) getBalance(on *getbalance.Layer,
func (cl *Engine) getBalance(on *getbalance.Layer,
b slice.Bytes, c *slice.Cursor, prev types.Onion) {
log.T.S(on)

View File

@@ -1,14 +1,15 @@
package client
package indra
import (
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/onion/layers/response"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/lnd/lnd/lnwire"
)
// response is a payload from an exit message.
func (cl *Client) response(on *response.Layer, b slice.Bytes,
func (cl *Engine) response(on *response.Layer, b slice.Bytes,
cur *slice.Cursor, prev types.Onion) {
pending := cl.PendingResponses.Find(on.Hash)

View File

@@ -1,16 +1,17 @@
package client
package indra
import (
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/crypto/ciph"
"github.com/indra-labs/indra/pkg/onion"
"github.com/indra-labs/indra/pkg/onion/layers/crypt"
"github.com/indra-labs/indra/pkg/onion/layers/reverse"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/lnd/lnd/lnwire"
)
func (cl *Client) reverse(on *reverse.Layer, b slice.Bytes,
func (cl *Engine) reverse(on *reverse.Layer, b slice.Bytes,
c *slice.Cursor, prev types.Onion) {
var e error

View File

@@ -1,16 +1,17 @@
package client
package indra
import (
"fmt"
"github.com/davecgh/go-spew/spew"
"github.com/indra-labs/indra/pkg/onion/layers/session"
"github.com/indra-labs/indra/pkg/traffic"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/util/slice"
)
func (cl *Client) session(on *session.Layer, b slice.Bytes,
func (cl *Engine) session(on *session.Layer, b slice.Bytes,
c *slice.Cursor, prev types.Onion) {
log.T.C(func() string {

View File

@@ -1,10 +1,11 @@
package client
package indra
import (
"fmt"
"reflect"
"github.com/davecgh/go-spew/spew"
"github.com/indra-labs/indra/pkg/onion"
"github.com/indra-labs/indra/pkg/onion/layers/balance"
"github.com/indra-labs/indra/pkg/onion/layers/confirm"
@@ -21,7 +22,7 @@ import (
"github.com/indra-labs/indra/pkg/util/slice"
)
func (cl *Client) handler() (out bool) {
func (cl *Engine) handler() (out bool) {
log.T.C(func() string {
return cl.AddrPort.String() +
" awaiting message"
@@ -56,7 +57,7 @@ func (cl *Client) handler() (out bool) {
return
}
func (cl *Client) handleMessage(b slice.Bytes, prev types.Onion) {
func (cl *Engine) handleMessage(b slice.Bytes, prev types.Onion) {
// process received message
var on types.Onion
var e error
@@ -102,7 +103,7 @@ func (cl *Client) handleMessage(b slice.Bytes, prev types.Onion) {
// utility functions
func recLog(on types.Onion, b slice.Bytes, cl *Client) func() string {
func recLog(on types.Onion, b slice.Bytes, cl *Engine) func() string {
return func() string {
return cl.AddrPort.String() +
" received " +

View File

@@ -1,13 +1,14 @@
package client
package indra
import (
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/node"
"github.com/indra-labs/indra/pkg/onion/layers/session"
"github.com/indra-labs/indra/pkg/payment"
"github.com/indra-labs/lnd/lnd/lnwire"
)
func (cl *Client) BuySessions(
func (cl *Engine) BuySessions(
s ...*SessionBuy) (sess []*session.Layer,
pmt []*payment.Payment) {

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"github.com/indra-labs/indra/pkg/crypto/key/cloak"
@@ -9,7 +9,7 @@ import (
// FindCloaked searches the client identity key and the sessions for a match. It
// returns the session as well, though not all users of this function will need
// this.
func (cl *Client) FindCloaked(clk cloak.PubKey) (hdr *prv.Key,
func (cl *Engine) FindCloaked(clk cloak.PubKey) (hdr *prv.Key,
pld *prv.Key, sess *traffic.Session, identity bool) {
var b cloak.Blinder

View File

@@ -1,14 +1,15 @@
package client
package indra
import (
"net/netip"
"github.com/davecgh/go-spew/spew"
"github.com/indra-labs/indra/pkg/util/slice"
)
// Send a message to a peer via their AddrPort.
func (cl *Client) Send(addr *netip.AddrPort, b slice.Bytes) {
func (cl *Engine) Send(addr *netip.AddrPort, b slice.Bytes) {
// first search if we already have the node available with connection
// open.
as := addr.String()

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"github.com/indra-labs/indra/pkg/onion"
@@ -6,7 +6,7 @@ import (
"github.com/indra-labs/indra/pkg/util/slice"
)
func (cl *Client) SendExit(port uint16, message slice.Bytes,
func (cl *Engine) SendExit(port uint16, message slice.Bytes,
target *traffic.Session, hook func(b slice.Bytes)) {
hops := []byte{0, 1, 2, 3, 4, 5}

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"github.com/indra-labs/indra/pkg/crypto/nonce"
@@ -6,7 +6,7 @@ import (
"github.com/indra-labs/indra/pkg/traffic"
)
func (cl *Client) SendGetBalance(s *traffic.Session, conf func(cf nonce.ID)) {
func (cl *Engine) SendGetBalance(s *traffic.Session, conf func(cf nonce.ID)) {
var c traffic.Circuit
var returns [3]*traffic.Session
hops := make([]byte, 0)

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"github.com/indra-labs/indra/pkg/crypto/nonce"
@@ -9,7 +9,7 @@ import (
"github.com/indra-labs/indra/pkg/traffic"
)
func (cl *Client) SendKeys(sb []*SessionBuy, sess []*session.Layer,
func (cl *Engine) SendKeys(sb []*SessionBuy, sess []*session.Layer,
pmt []*payment.Payment, hook func(hops []*traffic.Session)) {
if len(sb) != len(sess) || len(sess) != len(pmt) {

View File

@@ -1,8 +1,10 @@
package client
package indra
import (
"net/netip"
"github.com/indra-labs/lnd/lnd/lnwire"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/onion"
@@ -13,10 +15,9 @@ import (
"github.com/indra-labs/indra/pkg/onion/layers/getbalance"
"github.com/indra-labs/indra/pkg/onion/layers/reverse"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/lnd/lnd/lnwire"
)
func (cl *Client) SendOnion(ap *netip.AddrPort, o onion.Skins,
func (cl *Engine) SendOnion(ap *netip.AddrPort, o onion.Skins,
responseHook func(b slice.Bytes)) {
b := onion.Encode(o.Assemble())
var billable, accounted []nonce.ID

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"github.com/indra-labs/indra/pkg/crypto/nonce"
@@ -6,7 +6,7 @@ import (
"github.com/indra-labs/indra/pkg/traffic"
)
func (cl *Client) SendPing(c traffic.Circuit, conf func(cf nonce.ID)) {
func (cl *Engine) SendPing(c traffic.Circuit, conf func(cf nonce.ID)) {
hops := []byte{0, 1, 2, 3, 4, 5}
s := make(traffic.Sessions, len(hops))

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"sync"
@@ -6,6 +6,7 @@ import (
"time"
"github.com/cybriq/qu"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/node"
@@ -24,7 +25,7 @@ import (
func TestPing(t *testing.T) {
log2.SetLogLevel(log2.Trace)
const nTotal = 6
clients := make([]*Client, nTotal)
clients := make([]*Engine, nTotal)
var e error
if clients, e = CreateNMockCircuits(true, 1); check(e) {
t.Error(e)
@@ -67,7 +68,7 @@ func TestPing(t *testing.T) {
func TestSendExit(t *testing.T) {
log2.SetLogLevel(log2.Trace)
const nTotal = 6
clients := make([]*Client, nTotal)
clients := make([]*Engine, nTotal)
var e error
if clients, e = CreateNMockCircuits(true, 1); check(e) {
t.Error(e)
@@ -133,7 +134,7 @@ func TestSendExit(t *testing.T) {
func TestSendKeys(t *testing.T) {
log2.SetLogLevel(log2.Trace)
var clients []*Client
var clients []*Engine
var e error
if clients, e = CreateNMockCircuits(false, 1); check(e) {
t.Error(e)
@@ -187,7 +188,7 @@ func TestSendKeys(t *testing.T) {
func TestGetBalance(t *testing.T) {
log2.SetLogLevel(log2.Trace)
var clients []*Client
var clients []*Engine
var e error
if clients, e = CreateNMockCircuits(true, 2); check(e) {
t.Error(e)

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"github.com/indra-labs/indra/pkg/crypto/ciph"

View File

@@ -1,4 +1,4 @@
package client
package indra
import (
"math"
@@ -14,10 +14,10 @@ import (
)
func CreateNMockCircuits(inclSessions bool,
nCircuits int) (cl []*Client, e error) {
nCircuits int) (cl []*Engine, e error) {
nTotal := 1 + nCircuits*5
cl = make([]*Client, nTotal)
cl = make([]*Engine, nTotal)
nodes := make([]*node.Node, nTotal)
transports := make([]types.Transport, nTotal)
sessions := make(traffic.Sessions, nTotal-1)