tcpprox.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package tcpprox
  2. import "imuslab.com/zoraxy/mod/database"
  3. /*
  4. TCP Proxy
  5. Forward port from one port to another
  6. Also accept active connection and passive
  7. connection
  8. */
  9. const (
  10. ProxyMode_Listen = 0
  11. ProxyMode_Transport = 1
  12. ProxyMode_Starter = 2
  13. )
  14. type ProxyRelayConfig struct {
  15. UUID string //A UUIDv4 representing this config
  16. Name string //Name of the config
  17. Running bool //If the service is running
  18. PortA int //Ports A (config depends on mode)
  19. PortB int //Ports B (config depends on mode)
  20. Mode int //Operation Mode
  21. Timeout int //Timeout for connection
  22. StopChan chan bool //Stop channel to stop the listener
  23. }
  24. type Options struct {
  25. Database *database.Database
  26. }
  27. type Manager struct {
  28. //Config and stores
  29. Options *Options
  30. Configs []*ProxyRelayConfig
  31. //Realtime Statistics
  32. Connections int //currently connected connect counts
  33. AccumulatedByteTransfered int64 //The total number of bytes transfered
  34. }
  35. func NewTCProxy(options *Options) *Manager {
  36. options.Database.NewTable("tcprox")
  37. previousRules := []*ProxyRelayConfig{}
  38. if options.Database.KeyExists("tcprox", "rules") {
  39. options.Database.Read("tcprox", "rules", &previousRules)
  40. }
  41. return &Manager{
  42. Options: options,
  43. Configs: previousRules,
  44. Connections: 0,
  45. }
  46. }
  47. func (m *Manager) NewConfig(config *ProxyRelayConfig) error {
  48. return nil
  49. }
  50. func (m *Manager) RemoveConfig(configUUID string) error {
  51. return nil
  52. }
  53. func (m *Manager) SaveConfigToDatabase() {
  54. m.Options.Database.Write("tcprox", "rules", m.Configs)
  55. }