common_inet_proxy_handle.go 864 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package common
  2. import (
  3. "context"
  4. "github.com/cnlh/nps/core"
  5. "net"
  6. )
  7. type Proxy struct {
  8. core.NpsPlugin
  9. clientConn net.Conn
  10. ctx context.Context
  11. }
  12. func (proxy *Proxy) GetConfigName() *core.NpsConfigs {
  13. return core.NewNpsConfigs("socks5_proxy", "proxy to inet", core.CONFIG_LEVEL_PLUGIN)
  14. }
  15. func (proxy *Proxy) Run(ctx context.Context) (context.Context, error) {
  16. proxy.ctx = ctx
  17. proxy.clientConn = proxy.GetClientConn(ctx)
  18. clientId := proxy.GetClientId(ctx)
  19. brg := proxy.GetBridge(ctx)
  20. severConn, err := brg.GetConnByClientId(clientId)
  21. if err != nil {
  22. return ctx, err
  23. }
  24. // send connection information to the npc
  25. if _, err := core.SendInfo(severConn, nil); err != nil {
  26. return ctx, err
  27. }
  28. // data exchange
  29. go core.CopyBuffer(severConn, proxy.clientConn)
  30. core.CopyBuffer(proxy.clientConn, severConn)
  31. return ctx, core.REQUEST_EOF
  32. }