Ejemplo n.º 1
0
func run(port, password string) {
	//ln, err := net.Listen("tcp", ":"+port)
	ln, err := pipe.Listen(":" + port)
	if err != nil {
		log.Printf("error listening port %v: %v\n", port, err)
		os.Exit(1)
	}
	passwdManager.add(port, password, ln)
	var cipher *ss.Cipher
	log.Printf("server listening port %v ...\n", port)
	for {
		conn, err := ln.Accept()
		if err != nil {
			// listener maybe closed to update password
			debug.Printf("accept error: %v\n", err)
			return
		}
		// Creating cipher upon first connection.
		if cipher == nil {
			log.Println("creating cipher for port:", port)
			cipher, err = ss.NewCipher(config.Method, password)
			if err != nil {
				log.Printf("Error generating cipher for port: %s %v\n", port, err)
				conn.Close()
				continue
			}
		}
		go handleConnection(ss.NewConn(conn, cipher.Copy()))
	}
}
Ejemplo n.º 2
0
func DialWithRawAddrKCP(rawaddr []byte, server string, cipher *ss.Cipher) (c *ss.Conn, err error) {
	conn, err := pipe.Dial(server)
	if err != nil {
		return
	}
	c = ss.NewConn(conn, cipher)
	if _, err = c.Write(rawaddr); err != nil {
		c.Close()
		return nil, err
	}
	return
}