2015-09-07 12:49:40 +00:00
|
|
|
package net
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SocksServer is a SOCKS 5 proxy server
|
|
|
|
type SocksServer struct {
|
|
|
|
accepting bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (server *SocksServer) Listen(port uint8) error {
|
|
|
|
listener, err := net.Listen("tcp", ":"+string(port))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
server.accepting = true
|
2015-09-07 15:46:17 +00:00
|
|
|
go server.AcceptConnections(listener)
|
2015-09-07 12:49:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (server *SocksServer) AcceptConnections(listener net.Listener) error {
|
|
|
|
for server.accepting {
|
|
|
|
connection, err := listener.Accept()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
go server.HandleConnection(connection)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-07 15:46:17 +00:00
|
|
|
func (server *SocksServer) HandleConnection(connection net.Conn) error {
|
2015-09-07 12:49:40 +00:00
|
|
|
return nil
|
|
|
|
}
|