Merge branch 'protocol'

This commit is contained in:
l0k18
2023-06-20 12:14:47 +01:00
48 changed files with 571 additions and 442 deletions

View File

@@ -0,0 +1,19 @@
package client
import (
"github.com/spf13/cobra"
)
func Init(c *cobra.Command) {
c.AddCommand(clientCommand)
}
var clientCommand = &cobra.Command{
Use: "client",
Short: "run a client",
Long: "Runs indra as a client, providing a wireguard tunnel and socks5 " +
"proxy as connectivity options",
Run: func(cmd *cobra.Command, args []string) {
},
}

View File

@@ -1,68 +0,0 @@
package main
//
// import (
// "github.com/spf13/cobra"
// "github.com/spf13/viper"
//
// "github.com/indra-labs/indra"
// "github.com/indra-labs/indra/pkg/crypto/key/prv"
// "github.com/indra-labs/indra/pkg/crypto/key/pub"
// "github.com/indra-labs/indra/pkg/interrupt"
// log2 "github.com/indra-labs/indra/pkg/proc/log"
// "github.com/indra-labs/indra/pkg/relay"
// "github.com/indra-labs/indra/pkg/relay/transport"
// "github.com/indra-labs/indra/pkg/util/slice"
// )
//
// var (
// eng *relay.Engine
// engineP2P []string
// engineRPC []string
// )
//
// func init() {
// pf := relayCmd.PersistentFlags()
// pf.StringSliceVarP(&engineP2P, "engineP2P-relay", "P",
// []string{"127.0.0.1:8337", "::1:8337"},
// "address/ports for IPv4 and v6 listeners")
// pf.StringSliceVarP(&engineRPC, "relay-control", "r",
// []string{"127.0.0.1:8339", "::1:8339"},
// "address/ports for IPv4 and v6 listeners")
// viper.BindPFlag("engineP2P-relay", seedCommand.PersistentFlags().Lookup("engineP2P-relay"))
// viper.BindPFlag("relay-control", seedCommand.PersistentFlags().Lookup(
// "relay-control"))
// rootCmd.AddCommand(relayCmd)
// }
//
// var relayCmd = &cobra.Command{
// Use: "relay",
// Short: "Runs a relay server.",
// Long: `Runs a server that can be controlled with RPC and CLI interfaces.`,
// Run: func(cmd *cobra.Command, args []string) {
//
// log2.SetLogLevel(log2.Debug)
//
// log.I.Ln("-- ", log2.App, "("+viper.GetString(""+
// "network")+") -",
// indra.SemVer, "- Network Freedom. --")
//
// var e error
// var idPrv *prv.HiddenService
// if idPrv, e = prv.GenerateKey(); check(e) {
// return
// }
// idPub := pub.Derive(idPrv)
// nTotal := 5
// tpt := transport.NewSim(nTotal)
// addr := slice.GenerateRandomAddrPortIPv4()
// nod, _ := relay.NewNode(addr, idPub, idPrv, tpt, 50000, true)
// eng, e = relay.NewEngine(tpt, idPrv, nod, nil, 5)
// interrupt.AddHandler(func() { eng.Q() })
// log.D.Ln("starting up server")
// eng.Start()
// eng.Wait()
// log.I.Ln("fin")
// return
// },
// }

49
cmd/indra/relay/relay.go Normal file
View File

@@ -0,0 +1,49 @@
package relay
import (
"github.com/indra-labs/indra"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
log = log2.GetLogger()
check = log.E.Chk
)
var (
wireguardEnable bool
wireguardCIDR string // todo: there must be something like this. default route to 1
socksEnable bool
socksListener string
)
func Init(c *cobra.Command) {
relayCommand.PersistentFlags().BoolVarP(&wireguardEnable, "wireguard",
"w", false, "enable wireguard tunnel")
relayCommand.PersistentFlags().BoolVarP(&socksEnable, "socks",
"s", false, "enable socks proxy")
relayCommand.PersistentFlags().StringVarP(&socksListener, "socks-listener",
"l", "localhost:8080", "set address for socks 5 proxy listener")
viper.BindPFlag("wireguard", relayCommand.PersistentFlags().Lookup("wireguard"))
viper.BindPFlag("socks", relayCommand.PersistentFlags().Lookup("socks"))
viper.BindPFlag("socks-listener", relayCommand.PersistentFlags().Lookup("socks-listener"))
c.AddCommand(relayCommand)
}
var relayCommand = &cobra.Command{
Use: "relay",
Short: "run a relay",
Long: "Runs indra as a full relay, with optional client.",
Run: func(cmd *cobra.Command, args []string) {
log.I.Ln(log2.App.Load(), indra.SemVer)
nw, _ := cmd.Parent().PersistentFlags().GetString("network")
var dd string
dd, _ = cmd.Parent().PersistentFlags().GetString("data-dir")
log.T.S("cmd", dd, nw, args)
},
}

View File

@@ -3,8 +3,11 @@ package main
import (
"errors"
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/cmd/indra/client"
"github.com/indra-labs/indra/cmd/indra/relay"
"github.com/indra-labs/indra/cmd/indra/seed"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/appdata"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
@@ -13,7 +16,7 @@ import (
var indraTxt = `indra (` + indra.SemVer + `) - Network Freedom.
indra is a lightning powered, distributed virtual private network for anonymising traffic on decentralised protocol networks.
indra is a lightning powered, distributed virtual private network that protects you from metadata collection and enables novel service models.
`
var (
@@ -47,7 +50,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&cfgSave, "config-save", "", false, "saves the config file with any eligible envs/flags passed")
rootCmd.PersistentFlags().StringVarP(&logsDir, "logs-dir", "L", "", "logging directory (default is $HOME/.indra/logs)")
rootCmd.PersistentFlags().StringVarP(&logsLevel, "logs-level", "", "info", "set logging level off|fatal|error|warn|info|check|debug|trace")
rootCmd.PersistentFlags().StringVarP(&dataDir, "data-dir", "D", "", "data directory (default is $HOME/.indra/data)")
rootCmd.PersistentFlags().StringVarP(&dataDir, "data-dir", "D", appdata.Dir("indra", false), "data directory (default is $HOME/.indra/data)")
rootCmd.PersistentFlags().StringVarP(&network, "network", "N", "mainnet", "selects the network mainnet|testnet|simnet")
viper.BindPFlag("logs-dir", rootCmd.PersistentFlags().Lookup("logs-dir"))
@@ -55,17 +58,15 @@ func init() {
viper.BindPFlag("data-dir", rootCmd.PersistentFlags().Lookup("data-dir"))
viper.BindPFlag("network", rootCmd.PersistentFlags().Lookup("network"))
relay.Init(rootCmd)
client.Init(rootCmd)
seed.Init(rootCmd)
}
func initData() {
if viper.GetString("data-dir") == "" {
home, err := os.UserHomeDir()
cobra.CheckErr(err)
viper.Set("data-dir", home+"/.indra/data")
viper.Set("data-dir", appdata.Dir("indra", false))
}
}

View File

@@ -14,7 +14,7 @@ func init() {
var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version number",
Long: `All software has versions. This is Hugo's`,
Long: `All software has versions. This is mine. Semver formatted.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(indra.SemVer)
},

View File

@@ -2,10 +2,7 @@ package ad
import (
"github.com/indra-labs/indra/pkg/engine/coding"
"github.com/indra-labs/indra/pkg/engine/sess"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/cryptorand"
"github.com/indra-labs/indra/pkg/util/qu"
"github.com/indra-labs/indra/pkg/util/splice"
)
@@ -20,42 +17,4 @@ type Ad interface {
coding.Codec
Splice(s *splice.Splice)
Validate() bool
Gossip(sm *sess.Manager, c qu.C)
}
// Gossip writes a new Ad out to the p2p network.
//
// todo: this will be changed to use the engine host peer store. An interface
//
// will be required.
func Gossip(x Ad, sm *sess.Manager, c qu.C) {
done := qu.T()
msg := splice.New(x.Len())
if fails(x.Encode(msg)) {
return
}
nPeers := sm.NodesLen()
peerIndices := make([]int, nPeers)
for i := 1; i < nPeers; i++ {
peerIndices[i] = i
}
cryptorand.Shuffle(nPeers, func(i, j int) {
peerIndices[i], peerIndices[j] = peerIndices[j], peerIndices[i]
})
var cursor int
for {
select {
case <-c.Wait():
return
case <-done:
return
default:
}
n := sm.FindNodeByIndex(peerIndices[cursor])
n.Transport.Send(msg.GetAll())
cursor++
if cursor > len(peerIndices)-1 {
break
}
}
}

128
pkg/engine/ads/ads.go Normal file
View File

@@ -0,0 +1,128 @@
package ads
import (
"errors"
"github.com/indra-labs/indra/pkg/crypto"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/engine/node"
"github.com/indra-labs/indra/pkg/engine/payments"
"github.com/indra-labs/indra/pkg/engine/services"
"github.com/indra-labs/indra/pkg/onions/adaddress"
"github.com/indra-labs/indra/pkg/onions/adload"
"github.com/indra-labs/indra/pkg/onions/adpeer"
"github.com/indra-labs/indra/pkg/onions/adproto"
"github.com/indra-labs/indra/pkg/onions/adservices"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/multi"
"github.com/multiformats/go-multiaddr"
"net/netip"
"time"
)
var (
log = log2.GetLogger()
fails = log.E.Chk
)
const DefaultAdExpiry = time.Hour * 24 * 7 // one week
type NodeAds struct {
Peer *adpeer.Ad
Address *adaddress.Ad
Services *adservices.Ad
Load *adload.Ad
}
func GetMultiaddr(n *node.Node) (ma multiaddr.Multiaddr, e error) {
if ma, e = multi.AddrFromAddrPort(*n.AddrPort); fails(e) {
return
}
ma = multi.AddKeyToMultiaddr(ma, n.Identity.Pub)
return
}
func GenerateAds(n *node.Node, load byte) (na *NodeAds, e error) {
expiry := time.Now().Add(DefaultAdExpiry)
var svcs []adservices.Service
for i := range n.Services {
svcs = append(svcs, adservices.Service{
Port: n.Services[i].Port,
RelayRate: n.Services[i].RelayRate,
})
}
var ma multiaddr.Multiaddr
if ma, e = GetMultiaddr(n); fails(e) {
return
}
na = &NodeAds{
Peer: &adpeer.Ad{
Ad: adproto.Ad{
ID: nonce.NewID(),
Key: n.Identity.Pub,
Expiry: expiry,
},
RelayRate: n.RelayRate,
},
Address: &adaddress.Ad{
Ad: adproto.Ad{
ID: nonce.NewID(),
Key: n.Identity.Pub,
Expiry: expiry,
},
Addr: ma,
},
Services: &adservices.Ad{
Ad: adproto.Ad{
ID: nonce.NewID(),
Key: n.Identity.Pub,
Expiry: expiry,
},
Services: svcs,
},
Load: &adload.Ad{
Ad: adproto.Ad{
ID: nonce.NewID(),
Key: n.Identity.Pub,
Expiry: time.Now().Add(time.Minute * 10),
},
Load: load,
},
}
return
}
const ErrNilNodeAds = "cannot process nil NodeAds"
func NodeFromAds(a *NodeAds) (n *node.Node, e error) {
if a == nil ||
a.Services == nil || a.Load == nil ||
a.Address == nil || a.Peer == nil {
return n, errors.New(ErrNilNodeAds)
}
var ap netip.AddrPort
if ap, e = multi.AddrToAddrPort(a.Address.Addr); fails(e) {
return
}
var svcs services.Services
for i := range a.Services.Services {
svcs = append(svcs, &services.Service{
Port: a.Services.Services[i].Port,
RelayRate: a.Services.Services[i].RelayRate,
Transport: nil, // todo: wen making?
})
}
n = &node.Node{
ID: nonce.NewID(),
AddrPort: &ap,
Identity: &crypto.Keys{
Pub: a.Address.Key,
Bytes: a.Address.Key.ToBytes(),
},
RelayRate: a.Peer.RelayRate,
Services: svcs,
Load: a.Load.Load,
PayChan: make(payments.PayChan, node.PaymentChanBuffers), // todo: other end stuff
Transport: nil, // this is populated when we dial it.
}
return
}

View File

@@ -29,12 +29,12 @@ func (ng *Engine) SendExit(port uint16, msg slice.Bytes, id nonce.ID,
s := make(sessions.Sessions, len(hops))
s[2] = bob
s[5] = alice
se := ng.Manager.SelectHops(hops, s, "exit")
se := ng.Mgr().SelectHops(hops, s, "exit")
var c sessions.Circuit
copy(c[:], se)
o := MakeExit(exit.ExitParams{port, msg, id, bob, alice, c, ng.KeySet})
res := PostAcctOnion(ng.Manager, o)
ng.Manager.SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
res := PostAcctOnion(ng.Mgr(), o)
ng.Mgr().SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
}
func (ng *Engine) SendGetBalance(alice, bob *sessions.Data, hook responses.Callback) {
@@ -42,14 +42,14 @@ func (ng *Engine) SendGetBalance(alice, bob *sessions.Data, hook responses.Callb
s := make(sessions.Sessions, len(hops))
s[2] = bob
s[5] = alice
se := ng.Manager.SelectHops(hops, s, "sendgetbalance")
se := ng.Mgr().SelectHops(hops, s, "sendgetbalance")
var c sessions.Circuit
copy(c[:], se)
o := MakeGetBalance(getbalance.GetBalanceParams{alice.ID, alice, bob, c,
ng.KeySet})
log.D.S("sending out getbalance onion", o)
res := PostAcctOnion(ng.Manager, o)
ng.Manager.SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
res := PostAcctOnion(ng.Mgr(), o)
ng.Mgr().SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
}
func (ng *Engine) SendHiddenService(id nonce.ID, key *crypto.Prv,
@@ -60,18 +60,18 @@ func (ng *Engine) SendHiddenService(id nonce.ID, key *crypto.Prv,
hops := sess.StandardCircuit()
s := make(sessions.Sessions, len(hops))
s[2] = alice
se := ng.Manager.SelectHops(hops, s, "sendhiddenservice")
se := ng.Mgr().SelectHops(hops, s, "sendhiddenservice")
var c sessions.Circuit
copy(c[:], se[:len(c)])
in = adintro.New(id, key, alice.Node.AddrPort, relayRate, port, expiry)
o := MakeHiddenService(in, alice, bob, c, ng.KeySet)
log.D.F("%s sending out hidden service onion %s",
ng.Manager.GetLocalNodeAddressString(),
ng.Mgr().GetLocalNodeAddressString(),
color.Yellow.Sprint(alice.Node.AddrPort.String()))
res := PostAcctOnion(ng.Manager, o)
res := PostAcctOnion(ng.Mgr(), o)
ng.GetHidden().AddHiddenService(svc, key, in,
ng.Manager.GetLocalNodeAddressString())
ng.Manager.SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
ng.Mgr().GetLocalNodeAddressString())
ng.Mgr().SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
return
}
@@ -97,24 +97,24 @@ func (ng *Engine) SendIntroQuery(id nonce.ID, hsk *crypto.Pub,
s := make(sessions.Sessions, len(hops))
s[2] = bob
s[5] = alice
se := ng.Manager.SelectHops(hops, s, "sendintroquery")
se := ng.Mgr().SelectHops(hops, s, "sendintroquery")
var c sessions.Circuit
copy(c[:], se)
o := MakeIntroQuery(id, hsk, bob, alice, c, ng.KeySet)
res := PostAcctOnion(ng.Manager, o)
res := PostAcctOnion(ng.Mgr(), o)
log.D.Ln(res.ID)
ng.Manager.SendWithOneHook(c[0].Node.AddrPort, res, fn, ng.Responses)
ng.Mgr().SendWithOneHook(c[0].Node.AddrPort, res, fn, ng.Responses)
}
func (ng *Engine) SendMessage(mp *message.Message, hook responses.Callback) (id nonce.ID) {
// Add another two hops for security against unmasking.
preHops := []byte{0, 1}
oo := ng.Manager.SelectHops(preHops, mp.Forwards[:], "sendmessage")
oo := ng.Mgr().SelectHops(preHops, mp.Forwards[:], "sendmessage")
mp.Forwards = [2]*sessions.Data{oo[0], oo[1]}
o := []ont.Onion{mp}
res := PostAcctOnion(ng.Manager, o)
res := PostAcctOnion(ng.Mgr(), o)
log.D.Ln("sending out message onion")
ng.Manager.SendWithOneHook(mp.Forwards[0].Node.AddrPort, res, hook,
ng.Mgr().SendWithOneHook(mp.Forwards[0].Node.AddrPort, res, hook,
ng.Responses)
return res.ID
}
@@ -123,20 +123,20 @@ func (ng *Engine) SendPing(c sessions.Circuit, hook responses.Callback) {
hops := sess.StandardCircuit()
s := make(sessions.Sessions, len(hops))
copy(s, c[:])
se := ng.Manager.SelectHops(hops, s, "sendping")
se := ng.Mgr().SelectHops(hops, s, "sendping")
copy(c[:], se)
id := nonce.NewID()
o := Ping(id, se[len(se)-1], c, ng.KeySet)
res := PostAcctOnion(ng.Manager, o)
ng.Manager.SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
res := PostAcctOnion(ng.Mgr(), o)
ng.Mgr().SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
}
func (ng *Engine) SendRoute(k *crypto.Pub, ap *netip.AddrPort,
hook responses.Callback) {
ng.Manager.FindNodeByAddrPort(ap)
ng.Mgr().FindNodeByAddrPort(ap)
var ss *sessions.Data
ng.Manager.IterateSessions(func(s *sessions.Data) bool {
ng.Mgr().IterateSessions(func(s *sessions.Data) bool {
if s.Node.AddrPort.String() == ap.String() {
ss = s
return true
@@ -144,20 +144,20 @@ func (ng *Engine) SendRoute(k *crypto.Pub, ap *netip.AddrPort,
return false
})
if ss == nil {
log.E.Ln(ng.Manager.GetLocalNodeAddressString(),
log.E.Ln(ng.Mgr().GetLocalNodeAddressString(),
"could not find session for address", ap.String())
return
}
log.D.Ln(ng.Manager.GetLocalNodeAddressString(), "sending route",
log.D.Ln(ng.Mgr().GetLocalNodeAddressString(), "sending route",
k.ToBased32Abbreviated())
hops := sess.StandardCircuit()
s := make(sessions.Sessions, len(hops))
s[2] = ss
se := ng.Manager.SelectHops(hops, s, "sendroute")
se := ng.Mgr().SelectHops(hops, s, "sendroute")
var c sessions.Circuit
copy(c[:], se)
o := MakeRoute(nonce.NewID(), k, ng.KeySet, se[5], c[2], c)
res := PostAcctOnion(ng.Manager, o)
res := PostAcctOnion(ng.Mgr(), o)
log.D.Ln("sending out route request onion")
ng.Manager.SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
ng.Mgr().SendWithOneHook(c[0].Node.AddrPort, res, hook, ng.Responses)
}

View File

@@ -18,7 +18,7 @@ import (
func (ng *Engine) BuyNewSessions(amount lnwire.MilliSatoshi,
fn func()) (e error) {
var nodes [5]*node.Node
nodes = ng.Manager.SelectUnusedCircuit()
nodes = ng.Mgr().SelectUnusedCircuit()
for i := range nodes {
if nodes[i] == nil {
e = fmt.Errorf("failed to find nodes %d", i)
@@ -27,7 +27,7 @@ func (ng *Engine) BuyNewSessions(amount lnwire.MilliSatoshi,
}
// Get a random return hop session (index 5).
var returnSession *sessions.Data
returnHops := ng.Manager.GetSessionsAtHop(5)
returnHops := ng.Mgr().GetSessionsAtHop(5)
if len(returnHops) > 1 {
cryptorand.Shuffle(len(returnHops), func(i, j int) {
returnHops[i], returnHops[j] = returnHops[j], returnHops[i]
@@ -45,7 +45,7 @@ func (ng *Engine) BuyNewSessions(amount lnwire.MilliSatoshi,
var pendingConfirms int
for i := range nodes {
confirmChans[i] = nodes[i].
Chan.Send(amount, s[i].ID, s[i].PreimageHash())
PayChan.Send(amount, s[i].ID, s[i].PreimageHash())
pendingConfirms++
}
var success bool
@@ -78,12 +78,12 @@ func (ng *Engine) BuyNewSessions(amount lnwire.MilliSatoshi,
}
// todo: handle payment failures!
o := MakeSession(conf, s, returnSession, nodes[:], ng.KeySet)
res := PostAcctOnion(ng.Manager, o)
ng.Manager.SendWithOneHook(nodes[0].AddrPort, res, func(id nonce.ID,
res := PostAcctOnion(ng.Mgr(), o)
ng.Mgr().SendWithOneHook(nodes[0].AddrPort, res, func(id nonce.ID,
ifc interface{},
b slice.Bytes) (e error) {
ng.Manager.Lock()
defer ng.Manager.Unlock()
ng.Mgr().Lock()
defer ng.Mgr().Unlock()
var ss [5]*sessions.Data
for i := range nodes {
log.D.F("confirming and storing session at hop %d %s for %s with"+
@@ -93,9 +93,9 @@ func (ng *Engine) BuyNewSessions(amount lnwire.MilliSatoshi,
amount)
ss[i] = sessions.NewSessionData(s[i].ID, nodes[i], amount,
s[i].Header, s[i].Payload, byte(i))
ng.Manager.Add(ss[i])
ng.Manager.Sessions = append(ng.Manager.Sessions, ss[i])
ng.Manager.PendingPayments.Delete(s[i].PreimageHash())
ng.Mgr().Add(ss[i])
ng.Mgr().Sessions = append(ng.manager.Sessions, ss[i])
ng.Mgr().PendingPayments.Delete(s[i].PreimageHash())
}
fn()
return

View File

@@ -4,6 +4,7 @@ import (
"context"
"github.com/indra-labs/indra/pkg/crypto"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/engine/ads"
"github.com/indra-labs/indra/pkg/engine/node"
"github.com/indra-labs/indra/pkg/engine/responses"
"github.com/indra-labs/indra/pkg/engine/sess"
@@ -34,7 +35,8 @@ type (
ctx context.Context
cancel func()
Responses *responses.Pending
Manager *sess.Manager
manager *sess.Manager
NodeAds *ads.NodeAds
Listener *transport.Listener
PubSub *pubsub.PubSub
topic *pubsub.Topic
@@ -46,15 +48,63 @@ type (
ShuttingDown atomic.Bool
}
Params struct {
Transport tpt.Transport
Listener *transport.Listener
*crypto.Keys
Transport tpt.Transport
Listener *transport.Listener
Keys *crypto.Keys
Node *node.Node
Nodes []*node.Node
NReturnSessions int
}
)
// New creates a new Engine according to the Params given.
func New(p Params) (ng *Engine, e error) {
p.Node.Transport = p.Transport
p.Node.Identity = p.Keys
var ks *crypto.KeySet
if _, ks, e = crypto.NewSigner(); fails(e) {
return
}
ctx, cancel := context.WithCancel(context.Background())
ng = &Engine{
ctx: ctx,
cancel: cancel,
Responses: &responses.Pending{},
KeySet: ks,
Listener: p.Listener,
manager: sess.NewSessionManager(),
h: hidden.NewHiddenrouting(),
Pause: qu.T(),
}
if p.Listener != nil && p.Listener.Host != nil {
if ng.PubSub, e = pubsub.NewGossipSub(ctx, p.Listener.Host); fails(e) {
cancel()
return
}
if ng.topic, e = ng.PubSub.Join(PubSubTopic); fails(e) {
cancel()
return
}
if ng.sub, e = ng.topic.Subscribe(); fails(e) {
cancel()
return
}
log.T.Ln("subscribed to", PubSubTopic, "topic on gossip network")
}
if ng.NodeAds, e = ads.GenerateAds(p.Node, 25); fails(e) {
cancel()
return
}
ng.Mgr().AddNodes(append([]*node.Node{p.Node}, p.Nodes...)...)
// Add return sessions for receiving responses, ideally more of these
// will be generated during operation and rotated out over time.
for i := 0; i < p.NReturnSessions; i++ {
ng.Mgr().AddSession(sessions.NewSessionData(nonce.NewID(), p.Node, 0,
nil, nil, 5))
}
return
}
// Cleanup closes and flushes any resources the client opened that require sync
// in order to reopen correctly.
func (ng *Engine) Cleanup() {
@@ -67,7 +117,7 @@ func (ng *Engine) GetLoad() byte { return byte(ng.Load.Load()) }
func (ng *Engine) HandleMessage(s *splice.Splice, pr ont.Onion) {
log.D.F("%s handling received message",
ng.Manager.GetLocalNodeAddressString())
ng.Mgr().GetLocalNodeAddressString())
s.SetCursor(0)
s.Segments = s.Segments[:0]
on := reg.Recognise(s)
@@ -77,7 +127,7 @@ func (ng *Engine) HandleMessage(s *splice.Splice, pr ont.Onion) {
return
}
if pr != nil && on.Magic() != pr.Magic() {
log.D.S("",s.GetAll().ToBytes())
log.D.S("", s.GetAll().ToBytes())
}
m := on.GetOnion()
if m == nil {
@@ -90,28 +140,27 @@ func (ng *Engine) HandleMessage(s *splice.Splice, pr ont.Onion) {
}
}
func (ng *Engine) Handler() (out bool) {
func (ng *Engine) Handler() (terminate bool) {
log.T.C(func() string {
return ng.Manager.GetLocalNodeAddressString() + " awaiting message"
return ng.Mgr().GetLocalNodeAddressString() + " awaiting message"
})
var prev ont.Onion
select {
case <-ng.ctx.Done():
ng.Shutdown()
out = true
break
return true
case c := <-ng.Listener.Accept():
go func() {
log.D.Ln("new connection inbound (TODO):", c.Host.Addrs()[0])
log.D.Ln("new connection inbound (TODO):", c.Host.Addrs())
_ = c
}()
case b := <-ng.Manager.ReceiveToLocalNode():
case b := <-ng.Mgr().ReceiveToLocalNode():
s := splice.Load(b, slice.NewCursor())
ng.HandleMessage(s, prev)
case p := <-ng.Manager.GetLocalNode().Chan.Receive():
case p := <-ng.Mgr().GetLocalNode().PayChan.Receive():
log.D.F("incoming payment for %s: %v", p.ID, p.Amount)
topUp := false
ng.Manager.IterateSessions(func(s *sessions.Data) bool {
ng.Mgr().IterateSessions(func(s *sessions.Data) bool {
if s.Preimage == p.Preimage {
s.IncSats(p.Amount, false, "top-up")
topUp = true
@@ -121,29 +170,29 @@ func (ng *Engine) Handler() (out bool) {
return false
})
if !topUp {
ng.Manager.AddPendingPayment(p)
ng.Mgr().AddPendingPayment(p)
log.T.F("awaiting session keys for preimage %s session Keys %s",
p.Preimage, p.ID)
}
// For now if we received this we return true. Later this will wait with
// a timeout on the lnd node returning the success to trigger this.
// For now if we received this we return true. Later this will wait with a
// timeout on the ln node returning the success to trigger this.
p.ConfirmChan <- true
case <-ng.Pause:
log.D.Ln("pausing", ng.Manager.GetLocalNodeAddressString())
log.D.Ln("pausing", ng.Mgr().GetLocalNodeAddressString())
// For testing purposes we need to halt this Handler and discard channel
// messages.
out:
for {
select {
case <-ng.Manager.GetLocalNode().Chan.Receive():
case <-ng.Mgr().GetLocalNode().PayChan.Receive():
log.D.Ln("discarding payments while in pause")
case <-ng.Manager.ReceiveToLocalNode():
case <-ng.Mgr().ReceiveToLocalNode():
log.D.Ln("discarding messages while in pause")
case <-ng.ctx.Done():
break out
return true
case <-ng.Pause:
// This will then resume to the top level select.
log.D.Ln("unpausing", ng.Manager.GetLocalNodeAddressString())
log.D.Ln("unpausing", ng.Mgr().GetLocalNodeAddressString())
break out
}
}
@@ -151,16 +200,16 @@ func (ng *Engine) Handler() (out bool) {
return
}
func (ng *Engine) Keyset() *crypto.KeySet { return ng.KeySet }
func (ng *Engine) KillSwitch() <-chan struct{} { return ng.ctx.Done() }
func (ng *Engine) Mgr() *sess.Manager { return ng.Manager }
func (ng *Engine) Pending() *responses.Pending { return ng.Responses }
func (ng *Engine) SetLoad(load byte) { ng.Load.Store(uint32(load)) }
func (ng *Engine) Keyset() *crypto.KeySet { return ng.KeySet }
func (ng *Engine) WaitForShutdown() <-chan struct{} { return ng.ctx.Done() }
func (ng *Engine) Mgr() *sess.Manager { return ng.manager }
func (ng *Engine) Pending() *responses.Pending { return ng.Responses }
func (ng *Engine) SetLoad(load byte) { ng.Load.Store(uint32(load)) }
// Shutdown triggers the shutdown of the client and the Cleanup before
// finishing.
func (ng *Engine) Shutdown() {
log.T.Ln("shutting down", ng.Manager.GetLocalNodeAddress().String())
log.T.Ln("shutting down", ng.Mgr().GetLocalNodeAddress().String())
if ng.ShuttingDown.Load() {
return
}
@@ -182,44 +231,3 @@ func (ng *Engine) Start() {
}
}
}
func New(p Params) (c *Engine, e error) {
p.Node.Transport = p.Transport
p.Node.Identity = p.Keys
var ks *crypto.KeySet
if _, ks, e = crypto.NewSigner(); fails(e) {
return
}
ctx, cancel := context.WithCancel(context.Background())
c = &Engine{
ctx: ctx,
cancel: cancel,
Responses: &responses.Pending{},
KeySet: ks,
Listener: p.Listener,
Manager: sess.NewSessionManager(),
h: hidden.NewHiddenrouting(),
Pause: qu.T(),
}
if p.Listener.Host != nil {
if c.PubSub, e = pubsub.NewGossipSub(ctx, p.Listener.Host); fails(e) {
cancel()
return
}
if c.topic, e = c.PubSub.Join(PubSubTopic); fails(e) {
return
}
if c.sub, e = c.topic.Subscribe(); fails(e) {
return
}
log.T.Ln("subscribed to", PubSubTopic, "topic on gossip network")
}
c.Manager.AddNodes(append([]*node.Node{p.Node}, p.Nodes...)...)
// AddIntro a return session for receiving responses, ideally more of these
// will be generated during operation and rotated out over time.
for i := 0; i < p.NReturnSessions; i++ {
c.Manager.AddSession(sessions.NewSessionData(nonce.NewID(), p.Node, 0,
nil, nil, 5))
}
return
}

View File

@@ -35,12 +35,12 @@ func TestClient_SendExit(t *testing.T) {
t.FailNow()
}
client := clients[0]
log.D.Ln("client", client.Manager.GetLocalNodeAddressString())
log.D.Ln("client", client.Mgr().GetLocalNodeAddressString())
// set up forwarding port service
const port = 3455
sim := transport.NewByteChan(0)
for i := range clients {
e = clients[i].Manager.AddServiceToLocalNode(&services.Service{
e = clients[i].Mgr().AddServiceToLocalNode(&services.Service{
Port: port,
Transport: sim,
RelayRate: 58000,
@@ -66,7 +66,7 @@ func TestClient_SendExit(t *testing.T) {
t.Error("Exit test failed")
}()
out:
for i := 3; i < len(clients[0].Manager.Sessions)-1; i++ {
for i := 3; i < len(clients[0].Mgr().Sessions)-1; i++ {
wg.Add(1)
var msg slice.Bytes
if msg, _, e = tests.GenMessage(64, "request"); fails(e) {
@@ -80,8 +80,8 @@ out:
t.Error(e)
t.FailNow()
}
bob := clients[0].Manager.Sessions[i]
returnHops := client.Manager.GetSessionsAtHop(5)
bob := clients[0].Mgr().Sessions[i]
returnHops := client.Mgr().GetSessionsAtHop(5)
var alice *sessions.Data
if len(returnHops) > 1 {
cryptorand.Shuffle(len(returnHops), func(i, j int) {
@@ -105,7 +105,7 @@ out:
})
bb := <-clients[3].Mgr().GetLocalNode().ReceiveFrom(port)
log.T.S(bb.ToBytes())
if e = clients[3].Manager.SendFromLocalNode(port, respMsg); fails(e) {
if e = clients[3].Mgr().SendFromLocalNode(port, respMsg); fails(e) {
t.Error("fail send")
}
log.T.Ln("response sent")
@@ -151,11 +151,11 @@ func TestClient_SendPing(t *testing.T) {
t.Error("SendPing test failed")
}()
out:
for i := 3; i < len(clients[0].Manager.Sessions)-1; i++ {
for i := 3; i < len(clients[0].Mgr().Sessions)-1; i++ {
wg.Add(1)
var c sessions.Circuit
sess := clients[0].Manager.Sessions[i]
c[sess.Hop] = clients[0].Manager.Sessions[i]
sess := clients[0].Mgr().Sessions[i]
c[sess.Hop] = clients[0].Mgr().Sessions[i]
clients[0].SendPing(c,
func(id nonce.ID, ifc interface{}, b slice.Bytes) (e error) {
log.D.Ln("success")
@@ -219,8 +219,8 @@ func TestClient_SendSessionKeys(t *testing.T) {
counter.Dec()
}
wg.Wait()
for j := range clients[0].Manager.CircuitCache {
log.D.F("%d %s %v", i, j, clients[0].Manager.CircuitCache[j])
for j := range clients[0].Mgr().CircuitCache {
log.D.F("%d %s %v", i, j, clients[0].Mgr().CircuitCache[j])
}
quit.Q()
}

View File

@@ -44,7 +44,7 @@ func TestEngine_Message(t *testing.T) {
t.FailNow()
}
client := clients[0]
log.D.Ln("client", client.Manager.GetLocalNodeAddressString())
log.D.Ln("client", client.Mgr().GetLocalNodeAddressString())
// Start up the clients.
for _, v := range clients {
go v.Start()
@@ -89,9 +89,9 @@ func TestEngine_Message(t *testing.T) {
}
id := nonce.NewID()
_ = id
introducerHops := client.Manager.GetSessionsAtHop(2)
introducerHops := client.Mgr().GetSessionsAtHop(2)
var introducer *sessions.Data
returnHops := client.Manager.GetSessionsAtHop(5)
returnHops := client.Mgr().GetSessionsAtHop(5)
var returner *sessions.Data
_ = returner
if len(introducerHops) > 1 {
@@ -112,7 +112,7 @@ func TestEngine_Message(t *testing.T) {
returner = returnHops[0]
log.D.Ln("getting sessions for introducer...")
for i := range clients {
if introducer.Node.ID == clients[i].Manager.GetLocalNode().ID {
if introducer.Node.ID == clients[i].Mgr().GetLocalNode().ID {
for j := 0; j < nCircuits; j++ {
wg.Add(1)
counter.Inc()
@@ -217,7 +217,7 @@ func TestEngine_Route(t *testing.T) {
t.FailNow()
}
client := clients[0]
log.W.Ln("client", client.Manager.GetLocalNodeAddressString())
log.W.Ln("client", client.Mgr().GetLocalNodeAddressString())
// Start up the clients.
for _, v := range clients {
go v.Start()
@@ -262,9 +262,9 @@ func TestEngine_Route(t *testing.T) {
}
id := nonce.NewID()
_ = id
introducerHops := client.Manager.GetSessionsAtHop(2)
introducerHops := client.Mgr().GetSessionsAtHop(2)
var introducer *sessions.Data
returnHops := client.Manager.GetSessionsAtHop(5)
returnHops := client.Mgr().GetSessionsAtHop(5)
var returner *sessions.Data
_ = returner
if len(introducerHops) > 1 {
@@ -286,7 +286,7 @@ func TestEngine_Route(t *testing.T) {
const localPort = 25234
log.D.Ln("getting sessions for introducer...")
for i := range clients {
if introducer.Node.ID == clients[i].Manager.GetLocalNode().ID {
if introducer.Node.ID == clients[i].Mgr().GetLocalNode().ID {
for j := 0; j < nCircuits; j++ {
wg.Add(1)
counter.Inc()
@@ -397,8 +397,8 @@ func TestEngine_SendHiddenService(t *testing.T) {
return
}
id := nonce.NewID()
introducerHops := clients[0].Manager.GetSessionsAtHop(2)
returnHops := clients[0].Manager.GetSessionsAtHop(5)
introducerHops := clients[0].Mgr().GetSessionsAtHop(2)
returnHops := clients[0].Mgr().GetSessionsAtHop(5)
var introducer *sessions.Data
if len(introducerHops) > 1 {
cryptorand.Shuffle(len(introducerHops), func(i, j int) {

View File

@@ -60,8 +60,8 @@ func createNMockCircuits(inclSessions bool, nCircuits int,
}); fails(e) {
return
}
cl[i].Manager.SetLocalNodeAddress(nodes[i].AddrPort)
cl[i].Manager.SetLocalNode(nodes[i])
cl[i].Mgr().SetLocalNodeAddress(nodes[i].AddrPort)
cl[i].Mgr().SetLocalNode(nodes[i])
if inclSessions {
// Create a session for all but the first.
if i > 0 {
@@ -69,11 +69,11 @@ func createNMockCircuits(inclSessions bool, nCircuits int,
1<<16, nil, nil, byte((i-1)/nCircuits))
// AddIntro session to node, so it will be able to relay if it
// gets a message with the key.
cl[i].Manager.AddSession(ss[i-1])
cl[i].Mgr().AddSession(ss[i-1])
// we need a copy for the node so the balance adjustments don't
// double up.
s := *ss[i-1]
cl[0].Manager.AddSession(&s)
cl[0].Mgr().AddSession(&s)
}
}
}
@@ -83,7 +83,7 @@ func createNMockCircuits(inclSessions bool, nCircuits int,
if i == j {
continue
}
cl[i].Manager.AddNodes(nodes[j])
cl[i].Mgr().AddNodes(nodes[j])
}
}
return

View File

@@ -29,23 +29,24 @@ type Node struct {
sync.Mutex
AddrPort *netip.AddrPort
Identity *crypto.Keys
RelayRate int // Base relay price mSAT/Mb.
RelayRate uint32 // Base relay price mSAT/Mb.
Services services.Services // Services offered by this peer.
payments.Chan
Load byte
payments.PayChan
Transport tpt.Transport
}
// NewNode creates a new Node. The transport should be from either dialing out or
// a peer dialing in and the self model does not need to do this.
func NewNode(addr *netip.AddrPort, keys *crypto.Keys, tpt tpt.Transport,
relayRate int) (n *Node, id nonce.ID) {
relayRate uint32) (n *Node, id nonce.ID) {
id = nonce.NewID()
n = &Node{
ID: id,
AddrPort: addr,
Identity: keys,
RelayRate: relayRate,
Chan: make(payments.Chan, PaymentChanBuffers),
PayChan: make(payments.PayChan, PaymentChanBuffers),
Transport: tpt,
}
return

View File

@@ -11,7 +11,7 @@ func (p PendingPayments) Add(np *Payment) (pp PendingPayments) {
}
type (
Chan chan *Payment
PayChan chan *Payment
Payment struct {
ID nonce.ID
Preimage sha256.Hash
@@ -53,11 +53,11 @@ func (p PendingPayments) FindPreimage(pi sha256.Hash) (pp *Payment) {
return
}
// Receive waits on receiving a Payment on a Chan.
func (pc Chan) Receive() <-chan *Payment { return pc }
// Receive waits on receiving a Payment on a PayChan.
func (pc PayChan) Receive() <-chan *Payment { return pc }
// Send a payment on the Chan.
func (pc Chan) Send(amount lnwire.MilliSatoshi,
// Send a payment on the PayChan.
func (pc PayChan) Send(amount lnwire.MilliSatoshi,
id nonce.ID, preimage sha256.Hash) (confirmChan chan bool) {
confirmChan = make(chan bool)
pc <- &Payment{

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/indra-labs/indra/pkg/ad"
"github.com/indra-labs/indra/pkg/onions/adload"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/libp2p/go-libp2p/core/peer"
@@ -33,7 +34,6 @@ func (ng *Engine) RunAdHandler(handler func(p *pubsub.Message,
for {
var m *pubsub.Message
var e error
log.D.Ln("waiting for next message from gossip network")
if m, e = ng.sub.Next(ng.ctx); e != nil {
continue
}
@@ -62,66 +62,72 @@ func (ng *Engine) HandleAd(p *pubsub.Message, ctx context.Context) (e error) {
s := splice.NewFrom(p.Data)
c := reg.Recognise(s)
if c == nil {
return errors.New("message not recognised")
return errors.New("ad not recognised")
}
if e = c.Decode(s); fails(e) {
return
}
var ok bool
switch c.(type) {
case *adaddress.Ad:
log.D.Ln("received", reflect.TypeOf(c), "from gossip network")
if addr, ok := c.(*adaddress.Ad); !ok {
var addr *adaddress.Ad
if addr, ok = c.(*adaddress.Ad); !ok {
return fmt.Errorf(ErrWrongTypeDecode,
adaddress.Magic, reflect.TypeOf(c).String())
} else {
// If we got to here now we can add to the PeerStore.
log.D.S("new ad for address:", c)
var id peer.ID
if id, e = peer.IDFromPublicKey(addr.Key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, "services", s.GetAll().ToBytes()); fails(e) {
return
}
} else if !addr.Validate() {
return errors.New("addr ad failed validation")
}
// If we got to here now we can add to the PeerStore.
log.D.S("new ad for address:", c)
var id peer.ID
if id, e = peer.IDFromPublicKey(addr.Key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, adaddress.Magic, s.GetAll().ToBytes()); fails(e) {
return
}
case *adintro.Ad:
log.D.Ln("received", reflect.TypeOf(c), "from gossip network")
if intr, ok := c.(*adintro.Ad); !ok {
var intr *adintro.Ad
if intr, ok = c.(*adintro.Ad); !ok {
return fmt.Errorf(ErrWrongTypeDecode,
adintro.Magic, reflect.TypeOf(c).String())
} else {
// If we got to here now we can add to the PeerStore.
log.D.S("new ad for intro:", c)
var id peer.ID
if id, e = peer.IDFromPublicKey(intr.Key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, "services", s.GetAll().ToBytes()); fails(e) {
return
}
} else if !intr.Validate() {
return errors.New("intro ad failed validation")
}
// If we got to here now we can add to the PeerStore.
log.D.S("new ad for intro:", c)
var id peer.ID
if id, e = peer.IDFromPublicKey(intr.Key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, adintro.Magic, s.GetAll().ToBytes()); fails(e) {
return
}
case *adload.Ad:
log.D.Ln("received", reflect.TypeOf(c), "from gossip network")
if lod, ok := c.(*adload.Ad); !ok {
var lod *adload.Ad
if lod, ok = c.(*adload.Ad); !ok {
return fmt.Errorf(ErrWrongTypeDecode,
adaddress.Magic, reflect.TypeOf(c).String())
} else {
// If we got to here now we can add to the PeerStore.
log.D.S("new ad for load:", c)
var id peer.ID
if id, e = peer.IDFromPublicKey(lod.Key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, "services", s.GetAll().ToBytes()); fails(e) {
return
}
} else if !lod.Validate() {
return errors.New("load ad failed validation")
}
// If we got to here now we can add to the PeerStore.
log.D.S("new ad for load:", c)
var id peer.ID
if id, e = peer.IDFromPublicKey(lod.Key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, adservices.Magic, s.GetAll().ToBytes()); fails(e) {
return
}
case *adpeer.Ad:
log.D.Ln("received", reflect.TypeOf(c), "from gossip network")
var ok bool
var pa *adpeer.Ad
if pa, ok = c.(*adpeer.Ad); !ok {
return fmt.Errorf(ErrWrongTypeDecode,
@@ -136,26 +142,68 @@ func (ng *Engine) HandleAd(p *pubsub.Message, ctx context.Context) (e error) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, "peer", s.GetAll().ToBytes()); fails(e) {
Peerstore().Put(id, adpeer.Magic, s.GetAll().ToBytes()); fails(e) {
return
}
case *adservices.Ad:
log.D.Ln("received", reflect.TypeOf(c), "from gossip network")
if serv, ok := c.(*adservices.Ad); !ok {
var sa *adservices.Ad
if sa, ok = c.(*adservices.Ad); !ok {
return fmt.Errorf(ErrWrongTypeDecode,
adservices.Magic, reflect.TypeOf(c).String())
} else {
// If we got to here now we can add to the PeerStore.
log.D.S("new ad for services:", c)
var id peer.ID
if id, e = peer.IDFromPublicKey(serv.Key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, "services", s.GetAll().ToBytes()); fails(e) {
return
}
} else if !sa.Validate() {
return errors.New("services ad failed validation")
}
// If we got to here now we can add to the PeerStore.
log.D.S("new ad for services:", c)
var id peer.ID
if id, e = peer.IDFromPublicKey(sa.Key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, adservices.Magic, s.GetAll().ToBytes()); fails(e) {
return
}
}
return
}
func (ng *Engine) GetPeerRecord(id peer.ID, key string) (add ad.Ad, e error) {
var a interface{}
if a, e = ng.Listener.Host.Peerstore().Get(id, key); fails(e) {
return
}
var ok bool
var adb slice.Bytes
if adb, ok = a.(slice.Bytes); !ok {
e = errors.New("peer record did not decode slice.Bytes")
return
}
if len(adb) < 1 {
e = fmt.Errorf("record for peer ID %v key %s has expired", id, key)
}
s := splice.NewFrom(adb)
c := reg.Recognise(s)
if c == nil {
e = errors.New(key + " peer record not recognised")
return
}
if e = c.Decode(s); fails(e) {
return
}
if add, ok = c.(ad.Ad); !ok {
e = errors.New(key + " peer record did not decode as Ad")
}
return
}
func (ng *Engine) ClearPeerRecord(id peer.ID, key string) (e error) {
if _, e = ng.Listener.Host.Peerstore().Get(id, key); fails(e) {
return
}
if e = ng.Listener.Host.
Peerstore().Put(id, key, []byte{}); fails(e) {
return
}
return
}

View File

@@ -44,7 +44,7 @@ func TestEngine_PeerStore(t *testing.T) {
}
time.Sleep(time.Second)
newAddressAd := adaddress.New(nonce.NewID(),
engines[0].Manager.GetLocalNodeIdentityPrv(),
engines[0].Mgr().GetLocalNodeIdentityPrv(),
engines[0].Listener.Host.Addrs()[0],
time.Now().Add(time.Hour*24*7))
sa := splice.New(newAddressAd.Len())
@@ -56,8 +56,8 @@ func TestEngine_PeerStore(t *testing.T) {
}
time.Sleep(time.Second)
newIntroAd := adintro.New(nonce.NewID(),
engines[0].Manager.GetLocalNodeIdentityPrv(),
engines[0].Manager.GetLocalNodeAddress(),
engines[0].Mgr().GetLocalNodeIdentityPrv(),
engines[0].Mgr().GetLocalNodeAddress(),
20000, 443,
time.Now().Add(time.Hour*24*7))
si := splice.New(newIntroAd.Len())
@@ -69,7 +69,7 @@ func TestEngine_PeerStore(t *testing.T) {
}
time.Sleep(time.Second)
newLoadAd := adload.New(nonce.NewID(),
engines[0].Manager.GetLocalNodeIdentityPrv(),
engines[0].Mgr().GetLocalNodeIdentityPrv(),
17,
time.Now().Add(time.Hour*24*7))
sl := splice.New(newLoadAd.Len())
@@ -81,7 +81,7 @@ func TestEngine_PeerStore(t *testing.T) {
}
time.Sleep(time.Second)
newPeerAd := adpeer.New(nonce.NewID(),
engines[0].Manager.GetLocalNodeIdentityPrv(),
engines[0].Mgr().GetLocalNodeIdentityPrv(),
20000,
time.Now().Add(time.Hour*24*7))
log.D.S("peer ad", newPeerAd)
@@ -94,7 +94,7 @@ func TestEngine_PeerStore(t *testing.T) {
}
time.Sleep(time.Second * 1)
newServiceAd := adservices.New(nonce.NewID(),
engines[0].Manager.GetLocalNodeIdentityPrv(),
engines[0].Mgr().GetLocalNodeIdentityPrv(),
[]adservices.Service{{20000, 54321}},
time.Now().Add(time.Hour*24*7))
ss := splice.New(newServiceAd.Len())

View File

@@ -13,7 +13,7 @@ func MakeReplyHeader(ng *Engine) (returnHeader *hidden.ReplyHeader) {
rvKeys := ng.KeySet.Next3()
hops := []byte{3, 4, 5}
s := make(sessions.Sessions, len(hops))
ng.Manager.SelectHops(hops, s, "make message reply header")
ng.Mgr().SelectHops(hops, s, "make message reply header")
rt := &exit.Routing{
Sessions: [3]*sessions.Data{s[0], s[1], s[2]},
Keys: crypto.Privs{rvKeys[0], rvKeys[1], rvKeys[2]},

View File

@@ -27,7 +27,7 @@ func TestClient_SendGetBalance(t *testing.T) {
t.FailNow()
}
client := clients[0]
log.D.Ln("client", client.Manager.GetLocalNodeAddressString())
log.D.Ln("client", client.Mgr().GetLocalNodeAddressString())
// Start up the clients.
for _, v := range clients {
go v.Start()
@@ -46,7 +46,7 @@ func TestClient_SendGetBalance(t *testing.T) {
}()
i := 0
wg.Add(1)
returnHops := client.Manager.GetSessionsAtHop(5)
returnHops := client.Mgr().GetSessionsAtHop(5)
var returner *sessions.Data
if len(returnHops) > 1 {
cryptorand.Shuffle(len(returnHops), func(i, j int) {
@@ -55,9 +55,9 @@ func TestClient_SendGetBalance(t *testing.T) {
})
}
returner = returnHops[0]
clients[0].SendGetBalance(returner, clients[0].Manager.Sessions[i],
clients[0].SendGetBalance(returner, clients[0].Mgr().Sessions[i],
func(cf nonce.ID, ifc interface{}, b slice.Bytes) (e error) {
log.I.Ln("success")
log.D.Ln("success")
wg.Done()
quit.Q()
return

View File

@@ -5,7 +5,7 @@ import "github.com/indra-labs/indra/pkg/engine/tpt"
type (
Service struct {
Port uint16
RelayRate int
RelayRate uint32
tpt.Transport
}
Services []*Service

View File

@@ -399,13 +399,13 @@ func (sm *Manager) GetLocalNodeIdentityPrv() (ident *crypto.Prv) {
return sm.GetLocalNode().Identity.Prv
}
// GetLocalNodePaymentChan returns the engine's local Node Chan.
func (sm *Manager) GetLocalNodePaymentChan() payments.Chan {
return sm.nodes[0].Chan
// GetLocalNodePaymentChan returns the engine's local Node PayChan.
func (sm *Manager) GetLocalNodePaymentChan() payments.PayChan {
return sm.nodes[0].PayChan
}
// GetLocalNodeRelayRate returns the relay rate for the local node.
func (sm *Manager) GetLocalNodeRelayRate() (rate int) {
func (sm *Manager) GetLocalNodeRelayRate() (rate uint32) {
sm.Lock()
defer sm.Unlock()
return sm.GetLocalNode().RelayRate

View File

@@ -2,18 +2,15 @@ package adaddress
import (
"fmt"
"github.com/indra-labs/indra/pkg/ad"
"github.com/indra-labs/indra/pkg/crypto"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/engine/coding"
"github.com/indra-labs/indra/pkg/engine/magic"
"github.com/indra-labs/indra/pkg/engine/sess"
"github.com/indra-labs/indra/pkg/onions/adproto"
"github.com/indra-labs/indra/pkg/onions/reg"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/multi"
"github.com/indra-labs/indra/pkg/util/qu"
"github.com/indra-labs/indra/pkg/util/splice"
"github.com/multiformats/go-multiaddr"
"net/netip"
@@ -75,23 +72,16 @@ func (x *Ad) Encode(s *splice.Splice) (e error) {
func (x *Ad) GetOnion() interface{} { return x }
func (x *Ad) Gossip(sm *sess.Manager, c qu.C) {
log.D.F("propagating peer info for %s",
x.Key.ToBased32Abbreviated())
ad.Gossip(x, sm, c)
log.T.Ln("finished broadcasting peer info")
}
func (x *Ad) Len() int { return Len }
func (x *Ad) Magic() string { return Magic }
func (x *Ad) Splice(s *splice.Splice) {
x.SpliceWithoutSig(s)
x.SpliceNoSig(s)
s.Signature(x.Sig)
}
func (x *Ad) SpliceWithoutSig(s *splice.Splice) {
func (x *Ad) SpliceNoSig(s *splice.Splice) {
var e error
var ap netip.AddrPort
if ap, e = multi.AddrToAddrPort(x.Addr); fails(e) {
@@ -107,13 +97,13 @@ func (x *Ad) SpliceWithoutSig(s *splice.Splice) {
func (x *Ad) Validate() bool {
s := splice.New(Len - magic.Len)
x.SpliceWithoutSig(s)
x.SpliceNoSig(s)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
key, e := x.Sig.Recover(hash)
if fails(e) {
return false
}
if key.Equals(x.Key) {
if key.Equals(x.Key) && x.Expiry.After(time.Now()) {
return true
}
return false
@@ -133,7 +123,7 @@ func New(id nonce.ID, key *crypto.Prv,
Addr: ma,
}
s := splice.New(Len)
peerAd.SpliceWithoutSig(s)
peerAd.SpliceNoSig(s)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
var e error
if peerAd.Sig, e = crypto.Sign(key, hash); fails(e) {

View File

@@ -13,7 +13,6 @@ import (
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/engine/coding"
"github.com/indra-labs/indra/pkg/engine/magic"
"github.com/indra-labs/indra/pkg/engine/sess"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/indra/pkg/util/splice"
)
@@ -62,13 +61,6 @@ func (x *Ad) Encode(s *splice.Splice) (e error) {
func (x *Ad) GetOnion() interface{} { return x }
// Gossip means adding to the node's peer message list which will be gossiped by
// the libp2p network of Indra peers.
func (x *Ad) Gossip(sm *sess.Manager, c <-chan struct{}) {
log.D.F("propagating hidden service intro for %s",
x.Key.ToBased32Abbreviated())
}
func (x *Ad) Len() int { return Len }
func (x *Ad) Magic() string { return Magic }
@@ -125,25 +117,24 @@ func New(
) (in *Ad) {
pk := crypto.DerivePub(key)
s := splice.New(Len)
IntroSplice(s, id, pk, ap, relayRate, port, expires)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
var e error
var sign crypto.SigBytes
if sign, e = crypto.Sign(key, hash); fails(e) {
return nil
}
in = &Ad{
Ad: adproto.Ad{
ID: id,
Key: pk,
Expiry: time.Now().Add(adproto.TTL),
Sig: sign,
Expiry: expires,
},
AddrPort: ap,
RelayRate: relayRate,
Port: port,
}
s := splice.New(in.Len())
in.SpliceNoSig(s)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
var e error
if in.Sig, e = crypto.Sign(key, hash); fails(e) {
return nil
}
return
}

View File

@@ -6,12 +6,9 @@ import (
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/engine/coding"
"github.com/indra-labs/indra/pkg/engine/magic"
"github.com/indra-labs/indra/pkg/engine/sess"
"github.com/indra-labs/indra/pkg/onions/adintro"
"github.com/indra-labs/indra/pkg/onions/adproto"
"github.com/indra-labs/indra/pkg/onions/reg"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/qu"
"github.com/indra-labs/indra/pkg/util/splice"
"reflect"
"time"
@@ -24,7 +21,7 @@ var (
const (
Magic = "load"
Len = adproto.Len +1
Len = adproto.Len + 1
)
// Ad stores a specification for the fee rate and existence of a peer.
@@ -39,24 +36,22 @@ var _ coding.Codec = &Ad{}
func New(id nonce.ID, key *crypto.Prv, load byte,
expiry time.Time) (sv *Ad) {
s := splice.New(adintro.Len)
k := crypto.DerivePub(key)
Splice(s, id, k, load, expiry)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
var e error
var sign crypto.SigBytes
if sign, e = crypto.Sign(key, hash); fails(e) {
return nil
}
sv = &Ad{
Ad: adproto.Ad{
ID: id,
Key: k,
Expiry: time.Now().Add(adproto.TTL),
Sig: sign,
Expiry: expiry,
},
Load: load,
}
s := splice.New(sv.Len())
sv.SpliceNoSig(s)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
var e error
if sv.Sig, e = crypto.Sign(key, hash); fails(e) {
return nil
}
return
}
@@ -77,23 +72,10 @@ func (x *Ad) Encode(s *splice.Splice) (e error) {
func (x *Ad) GetOnion() interface{} { return nil }
func (x *Ad) Gossip(sm *sess.Manager, c qu.C) {}
func (x *Ad) Len() int { return Len }
func (x *Ad) Magic() string { return "" }
func (x *Ad) Sign(prv *crypto.Prv) (e error) {
s := splice.New(x.Len())
x.SpliceNoSig(s)
var b crypto.SigBytes
if b, e = crypto.Sign(prv, sha256.Single(s.GetUntil(s.GetCursor()))); fails(e) {
return
}
copy(x.Sig[:], b[:])
return nil
}
func (x *Ad) Splice(s *splice.Splice) {
x.SpliceNoSig(s)
s.Signature(x.Sig)
@@ -104,14 +86,14 @@ func (x *Ad) SpliceNoSig(s *splice.Splice) {
}
func (x *Ad) Validate() (valid bool) {
s := splice.New(adintro.Len - magic.Len)
s := splice.New(x.Len() - magic.Len)
x.SpliceNoSig(s)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
key, e := x.Sig.Recover(hash)
if fails(e) {
return false
}
if key.Equals(x.Key) {
if key.Equals(x.Key) && x.Expiry.After(time.Now()) {
return true
}
return false

View File

@@ -6,12 +6,10 @@ import (
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/engine/coding"
"github.com/indra-labs/indra/pkg/engine/magic"
"github.com/indra-labs/indra/pkg/engine/sess"
"github.com/indra-labs/indra/pkg/onions/adintro"
"github.com/indra-labs/indra/pkg/onions/adproto"
"github.com/indra-labs/indra/pkg/onions/reg"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/qu"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/indra/pkg/util/splice"
"reflect"
@@ -82,8 +80,6 @@ func (x *Ad) Encode(s *splice.Splice) (e error) {
func (x *Ad) GetOnion() interface{} { return nil }
func (x *Ad) Gossip(sm *sess.Manager, c qu.C) {}
func (x *Ad) Len() int { return Len }
func (x *Ad) Magic() string { return "" }

View File

@@ -1,16 +1,13 @@
package adproto
import (
"github.com/indra-labs/indra/pkg/ad"
"github.com/indra-labs/indra/pkg/crypto"
"github.com/indra-labs/indra/pkg/crypto/nonce"
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/engine/coding"
"github.com/indra-labs/indra/pkg/engine/magic"
"github.com/indra-labs/indra/pkg/engine/sess"
"github.com/indra-labs/indra/pkg/onions/reg"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/qu"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/indra/pkg/util/splice"
"reflect"
@@ -64,23 +61,16 @@ func (x *Ad) Encode(s *splice.Splice) (e error) {
func (x *Ad) GetOnion() interface{} { return x }
func (x *Ad) Gossip(sm *sess.Manager, c qu.C) {
log.D.F("propagating peer info for %s",
x.Key.ToBased32Abbreviated())
ad.Gossip(x, sm, c)
log.T.Ln("finished broadcasting peer info")
}
func (x *Ad) Len() int { return Len }
func (x *Ad) Magic() string { return Magic }
func (x *Ad) Splice(s *splice.Splice) {
x.SpliceWithoutSig(s)
x.SpliceNoSig(s)
s.Signature(x.Sig)
}
func (x *Ad) SpliceWithoutSig(s *splice.Splice) {
func (x *Ad) SpliceNoSig(s *splice.Splice) {
s.Magic(Magic).
ID(x.ID).
Pubkey(x.Key).
@@ -89,7 +79,7 @@ func (x *Ad) SpliceWithoutSig(s *splice.Splice) {
func (x *Ad) Validate() bool {
s := splice.New(Len)
x.SpliceWithoutSig(s)
x.SpliceNoSig(s)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
key, e := x.Sig.Recover(hash)
if fails(e) {
@@ -111,7 +101,7 @@ func New(id nonce.ID, key *crypto.Prv,
Expiry: expiry,
}
s := splice.New(Len - magic.Len)
protoAd.SpliceWithoutSig(s)
protoAd.SpliceNoSig(s)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
var e error
if protoAd.Sig, e = crypto.Sign(key, hash); fails(e) {

View File

@@ -7,12 +7,10 @@ import (
"github.com/indra-labs/indra/pkg/crypto/sha256"
"github.com/indra-labs/indra/pkg/engine/coding"
"github.com/indra-labs/indra/pkg/engine/magic"
"github.com/indra-labs/indra/pkg/engine/sess"
"github.com/indra-labs/indra/pkg/onions/adintro"
"github.com/indra-labs/indra/pkg/onions/adproto"
"github.com/indra-labs/indra/pkg/onions/reg"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/indra-labs/indra/pkg/util/qu"
"github.com/indra-labs/indra/pkg/util/slice"
"github.com/indra-labs/indra/pkg/util/splice"
"time"
@@ -49,24 +47,22 @@ var _ coding.Codec = &Ad{}
func New(id nonce.ID, key *crypto.Prv, services []Service,
expiry time.Time) (sv *Ad) {
s := splice.New(adintro.Len)
k := crypto.DerivePub(key)
ServiceSplice(s, id, k, services, expiry)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
var e error
var sign crypto.SigBytes
if sign, e = crypto.Sign(key, hash); fails(e) {
return nil
}
sv = &Ad{
Ad: adproto.Ad{
ID: id,
Key: k,
Expiry: time.Now().Add(adproto.TTL),
Sig: sign,
},
Services: services,
}
s := splice.New(adintro.Len)
sv.SpliceNoSig(s)
hash := sha256.Single(s.GetUntil(s.GetCursor()))
var e error
if sv.Sig, e = crypto.Sign(key, hash); fails(e) {
return nil
}
return
}
@@ -93,8 +89,6 @@ func (x *Ad) Encode(s *splice.Splice) (e error) {
func (x *Ad) GetOnion() interface{} { return nil }
func (x *Ad) Gossip(sm *sess.Manager, c qu.C) {}
func (x *Ad) Len() int { return adproto.Len + len(x.Services)*ServiceLen + slice.Uint32Len }
func (x *Ad) Magic() string { return "" }

View File

@@ -67,9 +67,9 @@ func (x *Balance) Handle(s *splice.Splice, p ont.Onion, ng ont.Ngin) (e error) {
log.D.S("found pending", pending.ID)
for i := range pending.Billable {
session := ng.Mgr().FindSessionByPubkey(pending.Billable[i])
out := session.Node.RelayRate * s.Len()
out := int(session.Node.RelayRate) * s.Len()
if session != nil {
in := session.Node.RelayRate * pending.SentSize
in := int(session.Node.RelayRate) * pending.SentSize
switch {
case i < 2:
ng.Mgr().DecSession(session.Header.Bytes, in, true, "reverse")

View File

@@ -71,7 +71,7 @@ func (x *Exit) Account(res *sess.Data, sm *sess.Manager,
res.PostAcct = append(res.PostAcct,
func() {
sm.DecSession(s.Header.Bytes,
s.Node.Services[j].RelayRate*len(res.B)/2, true, "exit")
int(s.Node.Services[j].RelayRate)*len(res.B)/2, true, "exit")
})
break
}
@@ -145,8 +145,8 @@ func (x *Exit) Handle(s *splice.Splice, p ont.Onion, ng ont.Ngin) (e error) {
sess.Node.Unlock()
continue
}
in := sess.Node.Services[i].RelayRate * s.Len() / 2
out := sess.Node.Services[i].RelayRate * rb.Len() / 2
in := int(sess.Node.Services[i].RelayRate) * s.Len() / 2
out := int(sess.Node.Services[i].RelayRate) * rb.Len() / 2
sess.Node.Unlock()
ng.Mgr().DecSession(sess.Header.Bytes, in+out, false, "exit")
break

View File

@@ -35,7 +35,7 @@ func (x *Forward) Account(res *sess.Data, sm *sess.Manager,
res.Billable = append(res.Billable, s.Header.Bytes)
res.PostAcct = append(res.PostAcct,
func() {
sm.DecSession(s.Header.Bytes, s.Node.RelayRate*len(res.B),
sm.DecSession(s.Header.Bytes, int(s.Node.RelayRate)*len(res.B),
true, "forward")
})
return
@@ -71,7 +71,7 @@ func (x *Forward) Handle(s *splice.Splice, p ont.Onion, ng ont.Ngin) (e error) {
sess := ng.Mgr().FindSessionByHeader(on1.ToPriv)
if sess != nil {
ng.Mgr().DecSession(sess.Header.Bytes,
ng.Mgr().GetLocalNodeRelayRate()*s.Len(),
int(ng.Mgr().GetLocalNodeRelayRate())*s.Len(),
false, "forward")
}
}

View File

@@ -109,8 +109,8 @@ func (x *GetBalance) Handle(s *splice.Splice, p ont.Onion, ng ont.Ngin) (e error
case *crypt.Crypt:
sess := ng.Mgr().FindSessionByHeader(on1.ToPriv)
if sess != nil {
in := sess.Node.RelayRate * s.Len() / 2
out := sess.Node.RelayRate * len(rb) / 2
in := int(sess.Node.RelayRate) * s.Len() / 2
out := int(sess.Node.RelayRate) * len(rb) / 2
ng.Mgr().DecSession(sess.Header.Bytes, in+out, false, "getbalance")
}
}

View File

@@ -97,7 +97,7 @@ func (x *HiddenService) Handle(s *splice.Splice, p ont.Onion, ng ont.Ngin) (e er
},
})
log.D.Ln("stored new introduction, starting broadcast")
go x.Intro.Gossip(ng.Mgr(), ng.KillSwitch())
// go x.Intro.Gossip(ng.Mgr(), ng.WaitForShutdown())
return
}

View File

@@ -103,8 +103,8 @@ func (x *IntroQuery) Handle(s *splice.Splice, p ont.Onion, ng ont.Ngin) (e error
case *crypt.Crypt:
sess := ng.Mgr().FindSessionByHeader(on1.ToPriv)
if sess != nil {
in := sess.Node.RelayRate * s.Len() / 2
out := sess.Node.RelayRate * rb.Len() / 2
in := int(sess.Node.RelayRate) * s.Len() / 2
out := int(sess.Node.RelayRate) * rb.Len() / 2
ng.Mgr().DecSession(sess.Header.Bytes, in+out, false, "introquery")
}
}

View File

@@ -25,7 +25,7 @@ type Ngin interface {
Mgr() *sess.Manager
Pending() *responses.Pending
GetHidden() *hidden.Hidden
KillSwitch() <-chan struct{}
WaitForShutdown() <-chan struct{}
Keyset() *crypto.KeySet
}

View File

@@ -94,7 +94,7 @@ func (x *Response) Handle(s *splice.Splice, p ont.Onion, ng ont.Ngin) (e error)
}
se.Node.Unlock()
}
ng.Mgr().DecSession(se.Header.Bytes, relayRate*dataSize, true, typ)
ng.Mgr().DecSession(se.Header.Bytes, int(relayRate)*dataSize, true, typ)
}
}
ng.Pending().ProcessAndDelete(x.ID, nil, x.Bytes)

View File

@@ -110,7 +110,7 @@ func (x *Reverse) Handle(s *splice.Splice, p ont.Onion, ng ont.Ngin) (e error) {
sess := ng.Mgr().FindSessionByHeader(hdr)
if sess != nil {
ng.Mgr().DecSession(sess.Header.Bytes,
ng.Mgr().GetLocalNodeRelayRate()*s.Len(), false, "reverse")
int(ng.Mgr().GetLocalNodeRelayRate())*s.Len(), false, "reverse")
ng.HandleMessage(splice.BudgeUp(s.SetCursor(start)), on)
}
} else if p != nil {

View File

@@ -1,9 +1,9 @@
package p2p
import (
"github.com/dgraph-io/badger/v3"
"github.com/indra-labs/indra/pkg/cfg"
"github.com/indra-labs/indra/pkg/storage"
"github.com/dgraph-io/badger/v3"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/multiformats/go-multiaddr"
"github.com/spf13/viper"

View File

@@ -403,7 +403,7 @@ func logPrint(
),
LevelSpecs[level].Colorizer(loc),
printFunc(),
LevelSpecs[level].Colorizer(timeText),
color.Black.Sprint(timeText),
)
s = strings.TrimSuffix(s, "\n")
fmt.Fprintln(writer, s)

View File

@@ -1,6 +1,7 @@
package multi
import (
"fmt"
"github.com/indra-labs/indra/pkg/crypto"
log2 "github.com/indra-labs/indra/pkg/proc/log"
"github.com/libp2p/go-libp2p/core/peer"
@@ -30,6 +31,20 @@ func AddrToAddrPort(ma multiaddr.Multiaddr) (ap netip.AddrPort, e error) {
return
}
func AddrFromAddrPort(ap netip.AddrPort) (ma multiaddr.Multiaddr, e error) {
var ipv string
if ap.Addr().Is6() {
ipv = "ip6"
} else {
ipv = "ip4"
}
if ma, e = multiaddr.NewMultiaddr(fmt.Sprintf("/%s/%s/tcp/%d",
ipv, ap.Addr().String(), ap.Port())); fails(e) {
return
}
return
}
func AddKeyToMultiaddr(in multiaddr.Multiaddr, pub *crypto.Pub) (ma multiaddr.Multiaddr) {
var pid peer.ID
var e error

View File

@@ -1,4 +0,0 @@
#!/usr/bin/zsh
cd /home/loki/work/loki/indra-labs/indra
export PATH=/home/loki/work/loki/indra-labs/indra/scripts:$PATH
zsh

7
scripts/cdwork.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/usr/bin/zsh
# populate ~/.workpath thus: `cd path/to/repo/root; pwd>~/.workpath
export INDRAROOT=$(cat ~/.workpath)
export PATH=$INDRAROOT/scripts:$PATH
# put the path of the root of the repository in ./scripts/path
cd $INDRAROOT
zsh

11
scripts/readme.md Executable file
View File

@@ -0,0 +1,11 @@
# scripts
populate ~/.workpath thus: `cd path/to/repo/root; pwd>~/.workpath`
add this to your `~/.bashrc` or `~/.zshrc`:
export PATH=$(cat ~/.workpath)/scripts:$HOME/sdk/go1.19.10/bin:$PATH
export GOBIN=$HOME/.local/bin
`source` the `rc` file or open a new terminal session and type `cdwork.sh` and you will have a number of useful commands
that handle paths and special build parameters to make the code locations work without hard coding them anywhere.

3
scripts/run.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env zsh
reset
go run -tags local -gcflags "all=-trimpath=$INDRAROOT" $1 $2 $3 $4 $5

3
scripts/runci.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env zsh
reset
go run -gcflags "all=-trimpath=$INDRAROOT" $1 $2 $3 $4 $5

View File

@@ -1,3 +1,3 @@
#!/usr/bin/env zsh
reset
go test -v -tags local -gcflags "all=-trimpath=/home/loki/work/loki/indra-labs/indra" $1 $2 $3 $4 $5
go test -v -tags local -gcflags "all=-trimpath=$INDRAROOT" $1 $2 $3 $4 $5

3
scripts/testci.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env zsh
reset
go test -v -gcflags "all=-trimpath=$INDRAROOT" $1 $2 $3 $4 $5

View File

@@ -1,3 +1,3 @@
#!/usr/bin/env zsh
cd pkg
go test -v -tags local -gcflags "all=-trimpath=/home/loki/work/loki/indra-labs/indra" ./...
go test -v -tags local -gcflags "all=-trimpath=$INDRAROOT" ./...

3
scripts/trace.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/usr/bin/env zsh
reset
go run -tags local -gcflags "all=-trimpath=$INDRAROOT" $1 --logs-level=trace $2 $3 $4 $5