github.com/geph-official/geph2@v0.22.6-0.20210211030601-f527cb59b0df/cmd/geph-exit/singlehop.go (about) 1 package main 2 3 import ( 4 "net" 5 "os" 6 "time" 7 8 "github.com/geph-official/geph2/libs/cshirt2" 9 "github.com/geph-official/geph2/libs/niaucchi4" 10 log "github.com/sirupsen/logrus" 11 ) 12 13 func mainSingleHop() { 14 defer os.Exit(0) 15 log.Infoln("<<< ENTERING SINGLE HOP MODE >>>") 16 log.Infoln("... All other arguments will be ignored!") 17 log.Infof("... PK = %x", pubkey) 18 //go shUDP() 19 shTCP() 20 21 } 22 23 func shTCP() { 24 tcpListener, err := net.Listen("tcp", singleHop) 25 if err != nil { 26 panic(err) 27 } 28 log.Infoln("... TCP on", tcpListener.Addr()) 29 for { 30 rawClient, err := tcpListener.Accept() 31 if err != nil { 32 continue 33 } 34 log.Debugln("SH client [TCP] @", rawClient.RemoteAddr()) 35 go func() { 36 rawClient.SetDeadline(time.Now().Add(time.Second * 10)) 37 client, err := cshirt2.Server(pubkey, false, rawClient) 38 if err != nil { 39 rawClient.Close() 40 return 41 } 42 rawClient.SetDeadline(time.Now().Add(time.Hour * 24)) 43 handle(client) 44 }() 45 } 46 } 47 48 func shUDP() { 49 udpsock, err := net.ListenPacket("udp", singleHop) 50 if err != nil { 51 panic(err) 52 } 53 udpsock.(*net.UDPConn).SetWriteBuffer(10 * 1024 * 1024) 54 udpsock.(*net.UDPConn).SetReadBuffer(10 * 1024 * 1024) 55 obfs := niaucchi4.ObfsListen(pubkey, udpsock, false) 56 log.Infoln("... UDP on", obfs.LocalAddr()) 57 kcpListener := niaucchi4.ListenKCP(obfs) 58 for { 59 rc, err := kcpListener.Accept() 60 if err != nil { 61 log.Println("error while accepting TCP:", err) 62 continue 63 } 64 log.Debugln("SH client [UDP roaming] @", rc.RemoteAddr()) 65 go handle(rc) 66 } 67 }