1
0

socks5_server.go 861 B

123456789101112131415161718192021222324252627282930313233343536
  1. package socks5
  2. import (
  3. "github.com/cnlh/nps/core"
  4. "github.com/cnlh/nps/lib/conn"
  5. "github.com/cnlh/nps/server/common"
  6. "net"
  7. "strconv"
  8. )
  9. type S5Server struct {
  10. globalConfig map[string]string
  11. clientConfig map[string]string
  12. pluginConfig map[string]string
  13. ServerIp string
  14. ServerPort int
  15. plugins *core.Plugins
  16. listener net.Listener
  17. }
  18. func NewS5Server(globalConfig, clientConfig, pluginConfig map[string]string) *S5Server {
  19. s5 := &S5Server{
  20. globalConfig: globalConfig,
  21. clientConfig: clientConfig,
  22. pluginConfig: pluginConfig,
  23. plugins: &core.Plugins{},
  24. }
  25. s5.plugins.Add(new(Handshake), new(Access), new(CheckAccess), new(Request), new(common.Proxy))
  26. return s5
  27. }
  28. func (s5 *S5Server) Start() error {
  29. return conn.NewTcpListenerAndProcess(s5.ServerIp+":"+strconv.Itoa(s5.ServerPort), func(c net.Conn) {
  30. }, &s5.listener)
  31. }