// relay udp data func (s *UDPRelay) relay(rawAddr []byte) (err error) { cg := mika.NewCryptoGenerator("aes-128-cfb", "123456") cipher := cg.NewCrypto() mikaConn, err := mika.DailWithRawAddr("udp", ":8080", rawAddr, cipher) if err != nil { return } defer mikaConn.Close() go protocols.Pipe(s.conn, mikaConn) protocols.Pipe(mikaConn, s.conn) return }
func main() { conf := utils.ParseSeverConf() for _, s := range conf.Server { se := &server{ address: fmt.Sprintf("%s:%d", s.Address, s.Port), cg: mika.NewCryptoGenerator(s.Method, s.Password), } servers = append(servers, se) } if len(servers) <= 0 { utils.Fatalf("Please configure server") } for _, localConf := range conf.Local { tcpServe(localConf) } }
func listen(serverInfo *utils.ServerConf) { nl, err := net.Listen("tcp", fmt.Sprintf("%s:%d", serverInfo.Address, serverInfo.Port)) if err != nil { utils.Fatalf("Create server error %s", err) } utils.Infof("Listen on %d\n", serverInfo.Port) cg := mika.NewCryptoGenerator(serverInfo.Method, serverInfo.Password) for { c, err := nl.Accept() if err != nil { utils.Errorf("Accept connection error %s", err) continue } go func() { tcpConn := &tcp.Conn{c, time.Duration(serverInfo.Timeout) * time.Second} handle(tcpConn, cg) }() } }