speed test

This commit is contained in:
Abhishek Kondur 2022-11-15 22:48:07 +05:30
parent 3f279119c7
commit a75879109a
4 changed files with 90 additions and 81 deletions

View file

@ -25,6 +25,7 @@ TODO:-
-> start remote conn after endpoint is updated -> start remote conn after endpoint is updated
--> -->
*/ */
var sent bool
type ProxyAction string type ProxyAction string
@ -76,6 +77,7 @@ func StartProxyManager(manageChan chan *ManagerAction) {
log.Printf("-------> PROXY-MANAGER: %+v\n", mI) log.Printf("-------> PROXY-MANAGER: %+v\n", mI)
switch mI.Action { switch mI.Action {
case AddInterface: case AddInterface:
common.IsRelay = mI.Payload.IsRelay common.IsRelay = mI.Payload.IsRelay
if mI.Payload.IsRelay { if mI.Payload.IsRelay {
mI.RelayPeers() mI.RelayPeers()

View file

@ -160,7 +160,7 @@ func StartSniffer(ctx context.Context, ifaceName, extClientAddr string, port int
if ip.DstIP.String() == extClientAddr || ip.SrcIP.String() == extClientAddr { if ip.DstIP.String() == extClientAddr || ip.SrcIP.String() == extClientAddr {
if ifacePeers, ok := common.PeerAddrMap[ifaceName]; ok { if ifacePeers, ok := common.PeerAddrMap[ifaceName]; ok {
if peerConf, ok := ifacePeers[ip.DstIP.String()]; ok { if peerConf, ok := ifacePeers[ip.DstIP.String()]; ok {
log.Println("-----> Fowarding PKT From ExtClient: ", extClientAddr, " to: ", peerConf.Config.RemoteProxyIP) log.Println("-----> Fowarding PKT From ExtClient: ", extClientAddr, " to: ", peerConf)
//server.NmProxyServer.Server.WriteTo(packet.Data(), ) //server.NmProxyServer.Server.WriteTo(packet.Data(), )
} }

View file

@ -25,6 +25,7 @@ func NewProxy(config Config) *Proxy {
// proxyToRemote proxies everything from Wireguard to the RemoteKey peer // proxyToRemote proxies everything from Wireguard to the RemoteKey peer
func (p *Proxy) ProxyToRemote() { func (p *Proxy) ProxyToRemote() {
buf := make([]byte, 1500) buf := make([]byte, 1500)
peers := common.WgIFaceMap[p.Config.WgInterface.Name]
go func() { go func() {
<-p.Ctx.Done() <-p.Ctx.Done()
log.Println("Closing connection for: ", p.LocalConn.LocalAddr().String()) log.Println("Closing connection for: ", p.LocalConn.LocalAddr().String())
@ -58,7 +59,8 @@ func (p *Proxy) ProxyToRemote() {
log.Println("ERRR READ: ", err) log.Println("ERRR READ: ", err)
continue continue
} }
peers := common.WgIFaceMap[p.Config.WgInterface.Name] go func() {
if peerI, ok := peers[p.Config.RemoteKey]; ok { if peerI, ok := peers[p.Config.RemoteKey]; ok {
var srcPeerKeyHash, dstPeerKeyHash string var srcPeerKeyHash, dstPeerKeyHash string
buf, n, srcPeerKeyHash, dstPeerKeyHash = packet.ProcessPacketBeforeSending(buf, n, peerI.Config.LocalKey, peerI.Config.Key) buf, n, srcPeerKeyHash, dstPeerKeyHash = packet.ProcessPacketBeforeSending(buf, n, peerI.Config.LocalKey, peerI.Config.Key)
@ -70,7 +72,7 @@ func (p *Proxy) ProxyToRemote() {
} else { } else {
log.Printf("Peer: %s not found in config\n", p.Config.RemoteKey) log.Printf("Peer: %s not found in config\n", p.Config.RemoteKey)
p.Cancel() p.Cancel()
continue return
} }
//test(n, buf) //test(n, buf)
@ -78,6 +80,8 @@ func (p *Proxy) ProxyToRemote() {
if err != nil { if err != nil {
log.Println("Failed to send to remote: ", err) log.Println("Failed to send to remote: ", err)
} }
}()
} }
} }
} }

View file

@ -59,6 +59,8 @@ func (p *ProxyServer) Listen(ctx context.Context) {
log.Println("RECV ERROR: ", err) log.Println("RECV ERROR: ", err)
continue continue
} }
go func() {
var srcPeerKeyHash, dstPeerKeyHash string var srcPeerKeyHash, dstPeerKeyHash string
n, srcPeerKeyHash, dstPeerKeyHash = packet.ExtractInfo(buffer, n) n, srcPeerKeyHash, dstPeerKeyHash = packet.ExtractInfo(buffer, n)
//log.Printf("--------> RECV PKT [DSTPORT: %d], [SRCKEYHASH: %s], SourceIP: [%s] \n", localWgPort, srcPeerKeyHash, source.IP.String()) //log.Printf("--------> RECV PKT [DSTPORT: %d], [SRCKEYHASH: %s], SourceIP: [%s] \n", localWgPort, srcPeerKeyHash, source.IP.String())
@ -90,7 +92,7 @@ func (p *ProxyServer) Listen(ctx context.Context) {
if err != nil { if err != nil {
log.Println("Failed to send to remote: ", err) log.Println("Failed to send to remote: ", err)
} }
continue return
} }
} else { } else {
if remoteMap, ok := common.RelayPeerMap[dstPeerKeyHash]; ok { if remoteMap, ok := common.RelayPeerMap[dstPeerKeyHash]; ok {
@ -101,7 +103,7 @@ func (p *ProxyServer) Listen(ctx context.Context) {
if err != nil { if err != nil {
log.Println("Failed to send to remote: ", err) log.Println("Failed to send to remote: ", err)
} }
continue return
} }
} }
@ -120,12 +122,12 @@ func (p *ProxyServer) Listen(ctx context.Context) {
_, err = peerI.Proxy.LocalConn.Write(buffer[:n]) _, err = peerI.Proxy.LocalConn.Write(buffer[:n])
if err != nil { if err != nil {
log.Println("Failed to proxy to Wg local interface: ", err) log.Println("Failed to proxy to Wg local interface: ", err)
continue return
} }
} }
} }
continue return
} }
// // forward to all interfaces // // forward to all interfaces
@ -141,6 +143,7 @@ func (p *ProxyServer) Listen(ctx context.Context) {
// } // }
// } // }
}()
} }
} }