github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/cmd/benchmark/benchmark.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"flag"
     6  	"net"
     7  
     8  	"github.com/Asutorufa/yuhaiin/pkg/net/netapi"
     9  	"github.com/Asutorufa/yuhaiin/pkg/net/proxy/socks5"
    10  	"github.com/Asutorufa/yuhaiin/pkg/utils/relay"
    11  )
    12  
    13  func main() {
    14  	l := flag.String("l", "", "listener")
    15  	t := flag.String("t", "", "target")
    16  	s := flag.String("s", "", "socks5")
    17  	flag.Parse()
    18  
    19  	sh, sp, err := net.SplitHostPort(*s)
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  
    24  	ta, err := netapi.ParseAddress(0, *t)
    25  	if err != nil {
    26  		panic(err)
    27  	}
    28  
    29  	lis, err := net.Listen("tcp", *l)
    30  	if err != nil {
    31  		panic(err)
    32  	}
    33  
    34  	p := socks5.Dial(sh, sp, "", "")
    35  
    36  	for {
    37  		conn, err := lis.Accept()
    38  		if err != nil {
    39  			panic(err)
    40  		}
    41  
    42  		go func() {
    43  			defer conn.Close()
    44  
    45  			lconn, err := p.Conn(context.TODO(), ta)
    46  			if err != nil {
    47  				panic(err)
    48  			}
    49  			defer lconn.Close()
    50  
    51  			relay.Relay(conn, lconn)
    52  		}()
    53  	}
    54  
    55  }