diff --git a/pkg/ad/ad.go b/pkg/ad/ad.go index b89087b5..c08b2942 100644 --- a/pkg/ad/ad.go +++ b/pkg/ad/ad.go @@ -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 - } - } } diff --git a/pkg/engine/ads.go b/pkg/engine/ads.go new file mode 100644 index 00000000..42146e0a --- /dev/null +++ b/pkg/engine/ads.go @@ -0,0 +1,72 @@ +package engine + +import ( + "github.com/indra-labs/indra/pkg/crypto/nonce" + "github.com/indra-labs/indra/pkg/engine/node" + "github.com/indra-labs/indra/pkg/onions/adaddress" + "github.com/indra-labs/indra/pkg/onions/adpeer" + "github.com/indra-labs/indra/pkg/onions/adproto" + "github.com/indra-labs/indra/pkg/onions/adservices" + "github.com/indra-labs/indra/pkg/util/multi" + "github.com/multiformats/go-multiaddr" + "time" +) + +const DefaultAdExpiry = time.Hour * 24 * 7 // one week + +type NodeAds struct { + Peer adpeer.Ad + Address adaddress.Ad + Services adservices.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) (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: uint32(n.Services[i].RelayRate), + }) + } + var ma multiaddr.Multiaddr + if ma, e = multi.AddrFromAddrPort(*n.AddrPort); fails(e) { + return + } + ma = multi.AddKeyToMultiaddr(ma, n.Identity.Pub) + 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, + }, + } + return +} diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 63088693..6369eaae 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -77,7 +77,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 { @@ -102,7 +102,7 @@ func (ng *Engine) Handler() (out bool) { break 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(): @@ -151,11 +151,11 @@ 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. @@ -183,6 +183,7 @@ func (ng *Engine) Start() { } } +// New creates a new Engine according to the Params given. func New(p Params) (c *Engine, e error) { p.Node.Transport = p.Transport p.Node.Identity = p.Keys @@ -201,7 +202,7 @@ func New(p Params) (c *Engine, e error) { h: hidden.NewHiddenrouting(), Pause: qu.T(), } - if p.Listener.Host != nil { + if p.Listener != nil && p.Listener.Host != nil { if c.PubSub, e = pubsub.NewGossipSub(ctx, p.Listener.Host); fails(e) { cancel() return @@ -215,7 +216,7 @@ func New(p Params) (c *Engine, e error) { 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 + // 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++ { c.Manager.AddSession(sessions.NewSessionData(nonce.NewID(), p.Node, 0, diff --git a/pkg/engine/node/node.go b/pkg/engine/node/node.go index a3079411..f6215f1c 100644 --- a/pkg/engine/node/node.go +++ b/pkg/engine/node/node.go @@ -29,7 +29,7 @@ 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 Transport tpt.Transport @@ -38,7 +38,7 @@ type Node struct { // 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, diff --git a/pkg/engine/peerstore.go b/pkg/engine/peerstore.go index 0bb5af59..8d6bad76 100644 --- a/pkg/engine/peerstore.go +++ b/pkg/engine/peerstore.go @@ -34,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 } @@ -198,7 +197,7 @@ func (ng *Engine) GetPeerRecord(id peer.ID, key string) (add ad.Ad, e error) { return } -func (ng *Engine) ClearPeerRecord(id peer.ID, key string) (add ad.Ad, e error) { +func (ng *Engine) ClearPeerRecord(id peer.ID, key string) (e error) { if _, e = ng.Listener.Host.Peerstore().Get(id, key); fails(e) { return } diff --git a/pkg/engine/services/services.go b/pkg/engine/services/services.go index 2ac49b75..8779b77a 100644 --- a/pkg/engine/services/services.go +++ b/pkg/engine/services/services.go @@ -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 diff --git a/pkg/engine/sess/sessionmanager.go b/pkg/engine/sess/sessionmanager.go index 3a1a5b7d..a3941c9a 100644 --- a/pkg/engine/sess/sessionmanager.go +++ b/pkg/engine/sess/sessionmanager.go @@ -405,7 +405,7 @@ func (sm *Manager) GetLocalNodePaymentChan() payments.Chan { } // 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 diff --git a/pkg/onions/adaddress/adaddress.go b/pkg/onions/adaddress/adaddress.go index d8a6ac18..0738a2fb 100644 --- a/pkg/onions/adaddress/adaddress.go +++ b/pkg/onions/adaddress/adaddress.go @@ -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,13 +72,6 @@ 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 } diff --git a/pkg/onions/adintro/adintro.go b/pkg/onions/adintro/adintro.go index d44aca50..ceee6724 100644 --- a/pkg/onions/adintro/adintro.go +++ b/pkg/onions/adintro/adintro.go @@ -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 } diff --git a/pkg/onions/adload/adload.go b/pkg/onions/adload/adload.go index 2870109a..eb90bb86 100644 --- a/pkg/onions/adload/adload.go +++ b/pkg/onions/adload/adload.go @@ -6,11 +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/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" @@ -74,8 +72,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 "" } diff --git a/pkg/onions/adpeer/adpeer.go b/pkg/onions/adpeer/adpeer.go index 780ae2e4..454d3680 100644 --- a/pkg/onions/adpeer/adpeer.go +++ b/pkg/onions/adpeer/adpeer.go @@ -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 "" } diff --git a/pkg/onions/adproto/adproto.go b/pkg/onions/adproto/adproto.go index 4705f774..e1442cf3 100644 --- a/pkg/onions/adproto/adproto.go +++ b/pkg/onions/adproto/adproto.go @@ -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,13 +61,6 @@ 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 } diff --git a/pkg/onions/adservices/adservices.go b/pkg/onions/adservices/adservices.go index 965fbf07..4b0c33c5 100644 --- a/pkg/onions/adservices/adservices.go +++ b/pkg/onions/adservices/adservices.go @@ -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" @@ -91,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 "" } diff --git a/pkg/onions/balance/balance.go b/pkg/onions/balance/balance.go index 7dbd571d..465dac37 100644 --- a/pkg/onions/balance/balance.go +++ b/pkg/onions/balance/balance.go @@ -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") diff --git a/pkg/onions/exit/exit.go b/pkg/onions/exit/exit.go index d7eb0fbc..745a599a 100644 --- a/pkg/onions/exit/exit.go +++ b/pkg/onions/exit/exit.go @@ -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 diff --git a/pkg/onions/forward/forward.go b/pkg/onions/forward/forward.go index 1817e92e..5ee6ab19 100644 --- a/pkg/onions/forward/forward.go +++ b/pkg/onions/forward/forward.go @@ -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") } } diff --git a/pkg/onions/getbalance/getbalance.go b/pkg/onions/getbalance/getbalance.go index 4f69a3c7..10763aa8 100644 --- a/pkg/onions/getbalance/getbalance.go +++ b/pkg/onions/getbalance/getbalance.go @@ -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") } } diff --git a/pkg/onions/hiddenservice/hiddenservice.go b/pkg/onions/hiddenservice/hiddenservice.go index d0be615d..301ebcb5 100644 --- a/pkg/onions/hiddenservice/hiddenservice.go +++ b/pkg/onions/hiddenservice/hiddenservice.go @@ -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 } diff --git a/pkg/onions/introquery/introquery.go b/pkg/onions/introquery/introquery.go index eff895b3..7a41a59f 100644 --- a/pkg/onions/introquery/introquery.go +++ b/pkg/onions/introquery/introquery.go @@ -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") } } diff --git a/pkg/onions/ont/interfaces.go b/pkg/onions/ont/interfaces.go index 41af47c8..af9db97a 100644 --- a/pkg/onions/ont/interfaces.go +++ b/pkg/onions/ont/interfaces.go @@ -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 } diff --git a/pkg/onions/response/response.go b/pkg/onions/response/response.go index 576be664..15227209 100644 --- a/pkg/onions/response/response.go +++ b/pkg/onions/response/response.go @@ -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) diff --git a/pkg/onions/reverse/reverse.go b/pkg/onions/reverse/reverse.go index 1952d596..e144cc15 100644 --- a/pkg/onions/reverse/reverse.go +++ b/pkg/onions/reverse/reverse.go @@ -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 { diff --git a/pkg/util/multi/multiaddr.go b/pkg/util/multi/multiaddr.go index 2bdac746..7b8eb78e 100644 --- a/pkg/util/multi/multiaddr.go +++ b/pkg/util/multi/multiaddr.go @@ -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