WIP: Cleanup
This commit is contained in:
@@ -8,8 +8,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"vppn/m"
|
||||
|
||||
"git.crumpington.com/lib/go/ratelimiter"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -40,7 +38,6 @@ type Remote struct {
|
||||
Globals
|
||||
RemotePeerIP byte // Immutable.
|
||||
|
||||
limiter *ratelimiter.Limiter
|
||||
dupCheck *dupCheck
|
||||
sendCounter uint64 // init to startupCount << 48. Atomic access only.
|
||||
|
||||
@@ -53,13 +50,9 @@ func newRemote(g Globals, remotePeerIP byte) *Remote {
|
||||
r := &Remote{
|
||||
Globals: g,
|
||||
RemotePeerIP: remotePeerIP,
|
||||
limiter: ratelimiter.New(ratelimiter.Config{
|
||||
FillPeriod: 20 * time.Millisecond,
|
||||
MaxWaitCount: 1,
|
||||
}),
|
||||
dupCheck: newDupCheck(0),
|
||||
sendCounter: uint64(time.Now().Unix()<<30) + 1,
|
||||
messages: make(chan any, 8),
|
||||
dupCheck: newDupCheck(0),
|
||||
sendCounter: uint64(time.Now().Unix()<<30) + 1,
|
||||
messages: make(chan any, 8),
|
||||
}
|
||||
r.config.Store(&remoteConfig{})
|
||||
return r
|
||||
@@ -88,7 +81,7 @@ func (r *Remote) updateConf(conf remoteConfig) {
|
||||
|
||||
func (r *Remote) sendUDP(b []byte, addr netip.AddrPort) {
|
||||
if _, err := r.SendUDP(b, addr); err != nil {
|
||||
r.logf("Failed to send URP packet: %v", err)
|
||||
r.logf("Failed to send UDP packet: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,15 +117,14 @@ func (r *Remote) SendDataTo(data []byte) {
|
||||
return
|
||||
}
|
||||
|
||||
if conf.Direct {
|
||||
r.sendDataDirect(conf, data)
|
||||
} else {
|
||||
r.sendDataRelayed(conf, data)
|
||||
}
|
||||
}
|
||||
// Direct:
|
||||
|
||||
// sendDataRelayed sends data to the remote via the relay.
|
||||
func (r *Remote) sendDataRelayed(conf remoteConfig, data []byte) {
|
||||
if conf.Direct {
|
||||
r.sendUDP(r.encryptData(conf, conf.Peer.PeerIP, data), conf.DirectAddr)
|
||||
return
|
||||
}
|
||||
|
||||
// Relayed:
|
||||
relay := r.RelayHandler.Load()
|
||||
|
||||
if relay == nil {
|
||||
@@ -143,11 +135,6 @@ func (r *Remote) sendDataRelayed(conf remoteConfig, data []byte) {
|
||||
relay.relayData(conf.Peer.PeerIP, r.encryptData(conf, conf.Peer.PeerIP, data))
|
||||
}
|
||||
|
||||
// sendDataDirect sends data to the remote directly.
|
||||
func (r *Remote) sendDataDirect(conf remoteConfig, data []byte) {
|
||||
r.sendUDP(r.encryptData(conf, conf.Peer.PeerIP, data), conf.DirectAddr)
|
||||
}
|
||||
|
||||
func (r *Remote) relayData(toIP byte, enc []byte) {
|
||||
conf := r.conf()
|
||||
if !conf.Up || !conf.Direct {
|
||||
@@ -158,11 +145,6 @@ func (r *Remote) relayData(toIP byte, enc []byte) {
|
||||
}
|
||||
|
||||
func (r *Remote) sendControl(conf remoteConfig, data []byte) {
|
||||
if err := r.limiter.Limit(); err != nil {
|
||||
r.logf("Rate limiter")
|
||||
return
|
||||
}
|
||||
|
||||
// Direct:
|
||||
|
||||
if conf.Direct {
|
||||
|
||||
Reference in New Issue
Block a user