eliminated nasty millisatoshi type, consolidated megabyte calc to one place
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package relay
|
||||
|
||||
import (
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/prv"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/pub"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/signer"
|
||||
@@ -25,18 +23,15 @@ func (eng *Engine) balance(on *balance.Layer,
|
||||
if s != nil {
|
||||
switch {
|
||||
case i < 2:
|
||||
in := s.RelayRate * lnwire.MilliSatoshi(
|
||||
pending.SentSize) / 1024 / 1024
|
||||
in := s.RelayRate *
|
||||
pending.SentSize
|
||||
eng.DecSession(s.ID, in, true, "reverse")
|
||||
case i == 2:
|
||||
in := s.RelayRate * lnwire.MilliSatoshi(
|
||||
pending.SentSize/2) / 1024 / 1024
|
||||
out := s.RelayRate * lnwire.MilliSatoshi(
|
||||
len(b)/2) / 1024 / 1024
|
||||
in := s.RelayRate * pending.SentSize / 2
|
||||
out := s.RelayRate * len(b) / 2
|
||||
eng.DecSession(s.ID, in+out, true, "getbalance")
|
||||
case i > 2:
|
||||
out := s.RelayRate * lnwire.MilliSatoshi(
|
||||
len(b)) / 1024 / 1024
|
||||
out := s.RelayRate * len(b)
|
||||
eng.DecSession(s.ID, out, true, "reverse")
|
||||
}
|
||||
}
|
||||
@@ -131,10 +126,8 @@ func (eng *Engine) getbalance(on *getbalance.Layer,
|
||||
case *crypt.Layer:
|
||||
sess := eng.FindSessionByHeader(on1.ToPriv)
|
||||
if sess != nil {
|
||||
in := sess.RelayRate *
|
||||
lnwire.MilliSatoshi(len(b)) / 2 / 1024 / 1024
|
||||
out := sess.RelayRate *
|
||||
lnwire.MilliSatoshi(len(rb)) / 2 / 1024 / 1024
|
||||
in := sess.RelayRate * len(b) / 2
|
||||
out := sess.RelayRate * len(rb) / 2
|
||||
eng.DecSession(sess.ID, in+out, false, "getbalance")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package relay
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/prv"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/pub"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/signer"
|
||||
@@ -96,9 +94,9 @@ func (eng *Engine) exit(ex *exit.Layer, b slice.Bytes,
|
||||
continue
|
||||
}
|
||||
in := sess.Services[i].RelayRate *
|
||||
lnwire.MilliSatoshi(len(b)) / 2 / 1024 / 1024
|
||||
len(b) / 2
|
||||
out := sess.Services[i].RelayRate *
|
||||
lnwire.MilliSatoshi(len(rb)) / 2 / 1024 / 1024
|
||||
len(rb) / 2
|
||||
eng.DecSession(sess.ID, in+out, false, "exit")
|
||||
break
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package relay
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/ciph"
|
||||
"git-indra.lan/indra-labs/indra/pkg/messages/confirm"
|
||||
"git-indra.lan/indra-labs/indra/pkg/messages/crypt"
|
||||
@@ -77,7 +75,7 @@ func (eng *Engine) forward(on *forward.Layer, b slice.Bytes,
|
||||
sess := eng.FindSessionByHeader(on1.ToPriv)
|
||||
if sess != nil {
|
||||
eng.DecSession(sess.ID,
|
||||
eng.GetLocalNodeRelayRate()*lnwire.MilliSatoshi(len(b))/1024/1024,
|
||||
eng.GetLocalNodeRelayRate()*len(b),
|
||||
false, "forward")
|
||||
}
|
||||
}
|
||||
@@ -110,7 +108,7 @@ func (eng *Engine) response(on *response.Layer, b slice.Bytes,
|
||||
}
|
||||
}
|
||||
}
|
||||
eng.DecSession(s.ID, relayRate*lnwire.MilliSatoshi(dataSize)/1024/1024, true, typ)
|
||||
eng.DecSession(s.ID, relayRate*dataSize, true, typ)
|
||||
}
|
||||
}
|
||||
eng.PendingResponses.Delete(on.ID, on.Bytes)
|
||||
@@ -161,7 +159,7 @@ func (eng *Engine) reverse(on *reverse.Layer, b slice.Bytes,
|
||||
sess := eng.FindSessionByHeader(hdr)
|
||||
if sess != nil {
|
||||
eng.DecSession(sess.ID,
|
||||
eng.GetLocalNodeRelayRate()*lnwire.MilliSatoshi(len(b))/1024/1024, false, "reverse")
|
||||
eng.GetLocalNodeRelayRate()*len(b), false, "reverse")
|
||||
eng.handleMessage(BudgeUp(b, start), on1)
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -3,7 +3,6 @@ package relay
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
"github.com/cybriq/qu"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/prv"
|
||||
@@ -202,10 +201,8 @@ func (eng *Engine) introquery(iq *introquery.Layer, b slice.Bytes,
|
||||
case *crypt.Layer:
|
||||
sess := eng.FindSessionByHeader(on1.ToPriv)
|
||||
if sess != nil {
|
||||
in := sess.RelayRate *
|
||||
lnwire.MilliSatoshi(len(b)) / 2 / 1024 / 1024
|
||||
out := sess.RelayRate *
|
||||
lnwire.MilliSatoshi(len(rb)) / 2 / 1024 / 1024
|
||||
in := sess.RelayRate * len(b) / 2
|
||||
out := sess.RelayRate * len(rb) / 2
|
||||
eng.DecSession(sess.ID, in+out, false, "introquery")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"net/netip"
|
||||
"sync"
|
||||
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/prv"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/pub"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/nonce"
|
||||
@@ -24,7 +22,7 @@ type Node struct {
|
||||
IdentityPub *pub.Key
|
||||
IdentityBytes pub.Bytes
|
||||
IdentityPrv *prv.Key
|
||||
RelayRate lnwire.MilliSatoshi // Base relay price/Mb.
|
||||
RelayRate int // Base relay price/Mb.
|
||||
Services service.Services // Services offered by this peer.
|
||||
HiddenServices Referrers // Hidden services known by peer.
|
||||
Load *ring.BufferLoad // Relay load.
|
||||
@@ -47,7 +45,7 @@ const (
|
||||
// available. The Node for a client's self should use true in the local
|
||||
// parameter to not initialise the peer state ring buffers as it won't use them.
|
||||
func NewNode(addr *netip.AddrPort, idPub *pub.Key, idPrv *prv.Key,
|
||||
tpt types.Transport, relayRate lnwire.MilliSatoshi,
|
||||
tpt types.Transport, relayRate int,
|
||||
local bool) (n *Node, id nonce.ID) {
|
||||
|
||||
id = nonce.NewID()
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/prv"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/pub"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/nonce"
|
||||
@@ -65,7 +63,7 @@ func (sm *SessionManager) AddServiceToLocalNode(s *service.Service) (e error) {
|
||||
return sm.GetLocalNode().AddService(s)
|
||||
}
|
||||
|
||||
func (sm *SessionManager) GetLocalNodeRelayRate() (rate lnwire.MilliSatoshi) {
|
||||
func (sm *SessionManager) GetLocalNodeRelayRate() (rate int) {
|
||||
sm.Lock()
|
||||
defer sm.Unlock()
|
||||
return sm.GetLocalNode().RelayRate
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"net/netip"
|
||||
"runtime"
|
||||
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/nonce"
|
||||
"git-indra.lan/indra-labs/indra/pkg/messages/balance"
|
||||
"git-indra.lan/indra-labs/indra/pkg/messages/confirm"
|
||||
@@ -74,12 +72,7 @@ func (eng *Engine) PostAcctOnion(o Skins) (res SendData) {
|
||||
case *forward.Layer:
|
||||
res.billable = append(res.billable, s.ID)
|
||||
res.postAcct = append(res.postAcct,
|
||||
func() {
|
||||
eng.DecSession(s.ID,
|
||||
s.RelayRate*
|
||||
lnwire.MilliSatoshi(len(res.b))/1024/1024, true,
|
||||
"forward")
|
||||
})
|
||||
func() { eng.DecSession(s.ID, s.RelayRate*len(res.b), true, "forward") })
|
||||
case *hiddenservice.Layer:
|
||||
res.last = on2.ID
|
||||
res.billable = append(res.billable, s.ID)
|
||||
@@ -93,12 +86,7 @@ func (eng *Engine) PostAcctOnion(o Skins) (res SendData) {
|
||||
}
|
||||
res.port = on2.Port
|
||||
res.postAcct = append(res.postAcct,
|
||||
func() {
|
||||
eng.DecSession(s.ID,
|
||||
s.Services[j].RelayRate*
|
||||
lnwire.MilliSatoshi(len(res.b)/2)/1024/1024,
|
||||
true, "exit")
|
||||
})
|
||||
func() { eng.DecSession(s.ID, s.Services[j].RelayRate*len(res.b)/2, true, "exit") })
|
||||
break
|
||||
}
|
||||
res.billable = append(res.billable, s.ID)
|
||||
|
||||
@@ -2,9 +2,9 @@ package relay
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/prv"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/key/pub"
|
||||
"git-indra.lan/indra-labs/indra/pkg/crypto/nonce"
|
||||
@@ -52,7 +52,7 @@ func (sm *SessionManager) ClearSessions() {
|
||||
|
||||
func (sm *SessionManager) IncSession(id nonce.ID, sats lnwire.MilliSatoshi,
|
||||
sender bool, typ string) {
|
||||
|
||||
|
||||
sess := sm.FindSession(id)
|
||||
if sess != nil {
|
||||
sm.Lock()
|
||||
@@ -60,21 +60,23 @@ func (sm *SessionManager) IncSession(id nonce.ID, sats lnwire.MilliSatoshi,
|
||||
sess.IncSats(sats, sender, typ)
|
||||
}
|
||||
}
|
||||
func (sm *SessionManager) DecSession(id nonce.ID, sats lnwire.MilliSatoshi,
|
||||
sender bool, typ string) bool {
|
||||
|
||||
func (sm *SessionManager) DecSession(id nonce.ID, sats int,
|
||||
sender bool, typ string) bool {
|
||||
|
||||
sess := sm.FindSession(id)
|
||||
if sess != nil {
|
||||
sm.Lock()
|
||||
defer sm.Unlock()
|
||||
return sess.DecSats(sats, sender, typ)
|
||||
return sess.DecSats(lnwire.MilliSatoshi(sats/1024/1024),
|
||||
sender, typ)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (sm *SessionManager) GetNodeCircuit(id nonce.ID) (sce *Circuit,
|
||||
exists bool) {
|
||||
|
||||
|
||||
sm.Lock()
|
||||
defer sm.Unlock()
|
||||
sce, exists = sm.SessionCache[id]
|
||||
@@ -183,7 +185,7 @@ func (sm *SessionManager) IterateSessions(fn func(s *Session) bool) {
|
||||
// Do not call SessionManager methods within this function.
|
||||
func (sm *SessionManager) IterateSessionCache(fn func(n *Node,
|
||||
c *Circuit) bool) {
|
||||
|
||||
|
||||
sm.Lock()
|
||||
defer sm.Unlock()
|
||||
out:
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"git-indra.lan/indra-labs/lnd/lnd/lnwire"
|
||||
|
||||
"git-indra.lan/indra-labs/indra/pkg/types"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
Port uint16
|
||||
RelayRate lnwire.MilliSatoshi
|
||||
RelayRate int
|
||||
types.Transport
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user