package tcpprox import "imuslab.com/zoraxy/mod/database" /* TCP Proxy Forward port from one port to another Also accept active connection and passive connection */ const ( ProxyMode_Listen = 0 ProxyMode_Transport = 1 ProxyMode_Starter = 2 ) type ProxyRelayConfig struct { UUID string //A UUIDv4 representing this config Name string //Name of the config Running bool //If the service is running PortA int //Ports A (config depends on mode) PortB int //Ports B (config depends on mode) Mode int //Operation Mode Timeout int //Timeout for connection StopChan chan bool //Stop channel to stop the listener } type Options struct { Database *database.Database } type Manager struct { //Config and stores Options *Options Configs []*ProxyRelayConfig //Realtime Statistics Connections int //currently connected connect counts AccumulatedByteTransfered int64 //The total number of bytes transfered } func NewTCProxy(options *Options) *Manager { options.Database.NewTable("tcprox") previousRules := []*ProxyRelayConfig{} if options.Database.KeyExists("tcprox", "rules") { options.Database.Read("tcprox", "rules", &previousRules) } return &Manager{ Options: options, Configs: previousRules, Connections: 0, } } func (m *Manager) NewConfig(config *ProxyRelayConfig) error { return nil } func (m *Manager) RemoveConfig(configUUID string) error { return nil } func (m *Manager) SaveConfigToDatabase() { m.Options.Database.Write("tcprox", "rules", m.Configs) }