mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-16 00:36:49 +08:00
speed test
This commit is contained in:
parent
8b81a4b1ec
commit
1434147279
2 changed files with 85 additions and 85 deletions
|
@ -31,6 +31,7 @@ func (p *Proxy) ProxyToRemote() {
|
||||||
log.Println("Closing connection for: ", p.LocalConn.LocalAddr().String())
|
log.Println("Closing connection for: ", p.LocalConn.LocalAddr().String())
|
||||||
p.LocalConn.Close()
|
p.LocalConn.Close()
|
||||||
}()
|
}()
|
||||||
|
buf := make([]byte, 65535)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-p.Ctx.Done():
|
case <-p.Ctx.Done():
|
||||||
|
@ -53,22 +54,22 @@ func (p *Proxy) ProxyToRemote() {
|
||||||
|
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
buf := make([]byte, 1500)
|
|
||||||
n, err := p.LocalConn.Read(buf)
|
n, err := p.LocalConn.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERRR READ: ", err)
|
log.Println("ERRR READ: ", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go func(buf []byte, n int) {
|
// go func(buf []byte, n int) {
|
||||||
|
|
||||||
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, _, _ = packet.ProcessPacketBeforeSending(buf, n, peerI.Config.LocalKey, peerI.Config.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("failed to process pkt before sending: ", err)
|
log.Println("failed to process pkt before sending: ", err)
|
||||||
}
|
}
|
||||||
log.Printf("PROXING TO REMOTE!!!---> %s >>>>> %s >>>>> %s [[ SrcPeerHash: %s, DstPeerHash: %s ]]\n",
|
// log.Printf("PROXING TO REMOTE!!!---> %s >>>>> %s >>>>> %s [[ SrcPeerHash: %s, DstPeerHash: %s ]]\n",
|
||||||
p.LocalConn.LocalAddr(), server.NmProxyServer.Server.LocalAddr().String(), p.RemoteConn.String(), srcPeerKeyHash, dstPeerKeyHash)
|
// p.LocalConn.LocalAddr(), server.NmProxyServer.Server.LocalAddr().String(), p.RemoteConn.String(), srcPeerKeyHash, dstPeerKeyHash)
|
||||||
} 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()
|
||||||
|
@ -80,7 +81,7 @@ 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)
|
||||||
}
|
}
|
||||||
}(buf, n)
|
// }(buf, n)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
@ -36,7 +35,7 @@ type ProxyServer struct {
|
||||||
func (p *ProxyServer) Listen(ctx context.Context) {
|
func (p *ProxyServer) Listen(ctx context.Context) {
|
||||||
|
|
||||||
// Buffer with indicated body size
|
// Buffer with indicated body size
|
||||||
|
buffer := make([]byte, 65535+32)
|
||||||
for {
|
for {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
@ -54,13 +53,13 @@ func (p *ProxyServer) Listen(ctx context.Context) {
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
// Read Packet
|
// Read Packet
|
||||||
buffer := make([]byte, 1532)
|
|
||||||
n, source, err := p.Server.ReadFromUDP(buffer)
|
n, source, err := p.Server.ReadFromUDP(buffer)
|
||||||
if err != nil { // in future log errors?
|
if err != nil { // in future log errors?
|
||||||
log.Println("RECV ERROR: ", err)
|
log.Println("RECV ERROR: ", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go func(buffer []byte, source *net.UDPAddr, n int) {
|
// go func(buffer []byte, source *net.UDPAddr, n int) {
|
||||||
|
|
||||||
var srcPeerKeyHash, dstPeerKeyHash string
|
var srcPeerKeyHash, dstPeerKeyHash string
|
||||||
n, srcPeerKeyHash, dstPeerKeyHash = packet.ExtractInfo(buffer, n)
|
n, srcPeerKeyHash, dstPeerKeyHash = packet.ExtractInfo(buffer, n)
|
||||||
|
@ -117,9 +116,9 @@ func (p *ProxyServer) Listen(ctx context.Context) {
|
||||||
if peerInfo, ok := common.PeerKeyHashMap[srcPeerKeyHash]; ok {
|
if peerInfo, ok := common.PeerKeyHashMap[srcPeerKeyHash]; ok {
|
||||||
if peers, ok := common.WgIFaceMap[peerInfo.Interface]; ok {
|
if peers, ok := common.WgIFaceMap[peerInfo.Interface]; ok {
|
||||||
if peerI, ok := peers[peerInfo.PeerKey]; ok {
|
if peerI, ok := peers[peerInfo.PeerKey]; ok {
|
||||||
log.Printf("PROXING TO LOCAL!!!---> %s <<<< %s <<<<<<<< %s [[ RECV PKT [SRCKEYHASH: %s], [DSTKEYHASH: %s], SourceIP: [%s] ]]\n",
|
// log.Printf("PROXING TO LOCAL!!!---> %s <<<< %s <<<<<<<< %s [[ RECV PKT [SRCKEYHASH: %s], [DSTKEYHASH: %s], SourceIP: [%s] ]]\n",
|
||||||
peerI.Proxy.LocalConn.RemoteAddr(), peerI.Proxy.LocalConn.LocalAddr(),
|
// peerI.Proxy.LocalConn.RemoteAddr(), peerI.Proxy.LocalConn.LocalAddr(),
|
||||||
fmt.Sprintf("%s:%d", source.IP.String(), source.Port), srcPeerKeyHash, dstPeerKeyHash, source.IP.String())
|
// fmt.Sprintf("%s:%d", source.IP.String(), source.Port), srcPeerKeyHash, dstPeerKeyHash, source.IP.String())
|
||||||
_, 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)
|
||||||
|
@ -144,7 +143,7 @@ func (p *ProxyServer) Listen(ctx context.Context) {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// }
|
// }
|
||||||
}(buffer, source, n)
|
// }(buffer, source, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue