Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eahydra committed Oct 12, 2015
1 parent 387e507 commit e85b46a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
7 changes: 3 additions & 4 deletions shadowsocks_client.go
Expand Up @@ -6,16 +6,14 @@ import (
"strconv"
)

// ShadowSocksClient implements ShadowSocks Client Protocol and combine with net.Conn
// so you can use ShadowSocksClient as net.Conn to read or write.
// ShadowSocksClient implements ShadowSocks Proxy Protocol
type ShadowSocksClient struct {
network string
address string
forward Dialer
}

// NewShadowSocksClient constructs one ShadowSocksClient.
// Call this function with conn that accept from net.Listener or from net.Dial
// NewShadowSocksClient return a new ShadowSocksClient that implements Dialer interface.
func NewShadowSocksClient(network, address string, forward Dialer) (*ShadowSocksClient, error) {
return &ShadowSocksClient{
network: network,
Expand All @@ -24,6 +22,7 @@ func NewShadowSocksClient(network, address string, forward Dialer) (*ShadowSocks
}, nil
}

// Dial return a new net.Conn that through proxy server establish with address
func (s *ShadowSocksClient) Dial(network, address string) (net.Conn, error) {
switch network {
case "tcp", "tcp4", "tcp6":
Expand Down
13 changes: 8 additions & 5 deletions socks4.go
Expand Up @@ -25,19 +25,20 @@ var socks4Errors = []string{
"request rejected because the client program and identd report different user-ids",
}

// SOCKS4Server implements SOCKS4 Server Protocol. but not support udp protocol.
// Socks4Server implements Socks4 Proxy Protocol(http://www.openssh.com/txt/socks4.protocol).
// Just support CONNECT command.
type Socks4Server struct {
forward Dialer
}

// NewSOCKS4Server constructs one SOCKS4Server
// NewSocks4Server returns a new Socks4Server that can serve from new clients.
func NewSocks4Server(forward Dialer) (*Socks4Server, error) {
return &Socks4Server{
forward: forward,
}, nil
}

// Run just listen at specify address and serve with incoming new client conn.
// Serve with net.Listener for clients.
func (s *Socks4Server) Serve(listener net.Listener) error {
for {
conn, err := listener.Accept()
Expand All @@ -53,15 +54,16 @@ func (s *Socks4Server) Serve(listener net.Listener) error {
}
}

// SOCKS4Client implement SOCKS4 Client Protocol. It combine with net.Conn,
// so you can use SOCKS4Client as net.Conn to read or write.
// Socks4Client implements Socks4 Proxy Protocol(http://www.openssh.com/txt/socks4.protocol).
type Socks4Client struct {
network string
address string
userID string
forward Dialer
}

// NewSocks4Client return a new Socks4Client that implements Dialer interface.
// network must be supported by forward, address is proxy server's address, userID can empty.
func NewSocks4Client(network, address, userID string, forward Dialer) (*Socks4Client, error) {
return &Socks4Client{
network: network,
Expand All @@ -71,6 +73,7 @@ func NewSocks4Client(network, address, userID string, forward Dialer) (*Socks4Cl
}, nil
}

// Dial return a new net.Conn if succeeded. network must be tcp, tcp4 or tcp6, address only is IPV4.
func (s *Socks4Client) Dial(network, address string) (net.Conn, error) {
switch network {
case "tcp", "tcp4", "tcp6":
Expand Down
9 changes: 5 additions & 4 deletions socks5_client.go
Expand Up @@ -47,8 +47,8 @@ var socks5Errors = []string{
"Address type not supported",
}

// SOCKS5Client implements SOCKS5 Client Protocol.
// You can use it as net.Conn to read/write.
// Socks5Client implements Socks5 Proxy Protocol(RFC 1928) Client Protocol.
// Just support CONNECT command, and support USERNAME/PASSWORD authentication methods(RFC 1929)
type Socks5Client struct {
network string
address string
Expand All @@ -57,8 +57,7 @@ type Socks5Client struct {
forward Dialer
}

// NewSOCKS5Client constructs one SOCKS5Client
// Call this function with conn that accept from net.Listener or from net.Dial
// NewSocks5Client return a new Socks5Client that implements Dialer interface.
func NewSocks5Client(network, address, user, password string, forward Dialer) (*Socks5Client, error) {
return &Socks5Client{
network: network,
Expand All @@ -69,6 +68,8 @@ func NewSocks5Client(network, address, user, password string, forward Dialer) (*
}, nil
}

// Dial return a new net.Conn that through the CONNECT command to establish connections with proxy server.
// adddress as RFC's requirements that can be IPV4, IPV6 and domain host, such as 8.8.8.8:999 or google.com:80
func (s *Socks5Client) Dial(network, address string) (net.Conn, error) {
switch network {
case "tcp", "tcp4", "tcp6":
Expand Down
6 changes: 3 additions & 3 deletions socks5_server.go
Expand Up @@ -2,19 +2,19 @@ package socks

import "net"

// SOCKS5Server implements SOCKS5 Server Protocol, but not support UDP and BIND command.
// Socks5Server implements Socks5 Proxy Protocol(RFC 1928), just support CONNECT command.
type Socks5Server struct {
forward Dialer
}

// NewSocks5Server constructs one SOCKS5Server with router.
// NewSocks5Server return a new Socks5Server
func NewSocks5Server(forward Dialer) (*Socks5Server, error) {
return &Socks5Server{
forward: forward,
}, nil
}

// Run begin accept incoming client conn and serve it.
// Serve with net.Listener for new incomming clients.
func (s *Socks5Server) Serve(listener net.Listener) error {
for {
conn, err := listener.Accept()
Expand Down

0 comments on commit e85b46a

Please sign in to comment.