Compare commits

...

4 Commits
v0.0.3 ... main

Author SHA1 Message Date
Sense T
7662ab4e08 fix bug 2022-09-10 10:44:27 +00:00
Sense T
8c2b78e30b bug fix 2022-09-10 09:51:30 +00:00
Sense T
6002e20080 safer close 2022-09-10 02:19:17 +00:00
Sense T
afc125cc1c log some message 2022-09-09 13:31:49 +00:00
3 changed files with 26 additions and 19 deletions

View File

@ -22,6 +22,7 @@ func (c *Connection) Read(p []byte) (int, error) {
if !ok {
return 0, c.Close()
}
c.logger.Trace("dataframe received: ", df)
return df.Read(p)
}
@ -42,11 +43,13 @@ func (c *Connection) Write(p []byte) (int, error) {
if err != nil {
return 0, err
}
c.logger.Trace("dataframe send: ", df)
c.TX <- df
return n, nil
}
func (c *Connection) Close() error {
defer c.logger.Tracef("connection closed")
var lock sync.Mutex
defer close(c.TX)
if !c.closed {

View File

@ -22,22 +22,17 @@ type Logger interface {
type logger struct{}
func (l *logger) Trace(args ...interface{})
func (l *logger) Tracef(format string, args ...interface{})
func (l *logger) Debug(args ...interface{})
func (l *logger) Debugf(format string, args ...interface{})
func (l *logger) Info(args ...interface{})
func (l *logger) Infof(format string, args ...interface{})
func (l *logger) Error(args ...interface{})
func (l *logger) Errorf(format string, args ...interface{})
func (l *logger) Fatal(args ...interface{})
func (l *logger) Fatalf(format string, args ...interface{})
func (l *logger) Panic(args ...interface{})
func (l *logger) Panicf(format string, args ...interface{})
func (l *logger) Trace(args ...interface{}) {}
func (l *logger) Tracef(format string, args ...interface{}) {}
func (l *logger) Debug(args ...interface{}) {}
func (l *logger) Debugf(format string, args ...interface{}) {}
func (l *logger) Info(args ...interface{}) {}
func (l *logger) Infof(format string, args ...interface{}) {}
func (l *logger) Error(args ...interface{}) {}
func (l *logger) Errorf(format string, args ...interface{}) {}
func (l *logger) Fatal(args ...interface{}) {}
func (l *logger) Fatalf(format string, args ...interface{}) {}
func (l *logger) Panic(args ...interface{}) {}
func (l *logger) Panicf(format string, args ...interface{}) {}
var DefaultLogger = &logger{}

View File

@ -25,6 +25,7 @@ func NewManager(tun io.ReadWriter) *Manager {
accept: make(chan *DataFrame, 1024),
newConnection: make(chan *Connection),
delConnection: make(chan *Connection),
closed: make(chan bool),
logger: DefaultLogger,
}
}
@ -34,18 +35,24 @@ func (m *Manager) SetLogger(logger Logger) {
}
func (m *Manager) Run() {
m.logger.Debug("manager run")
onReceiveQueue := make(chan bool)
for {
select {
case <-m.closed:
return
case df := <-m.incoming:
m.logger.Trace("dataframe->tunnel: ", df)
go df.Encode(m.Tunnel)
case connection := <-m.newConnection:
m.Connections[connection.ID] = connection
m.logger.Tracef("connection '%s' registered", connection.ID)
case connection := <-m.delConnection:
if !connection.closed {
connection.Close()
delete(m.Connections, connection.ID)
m.logger.Tracef("connection '%s' unregistered", connection.ID)
}
case onReceiveQueue <- true:
go m.onReceive(onReceiveQueue)
}
@ -58,6 +65,8 @@ func (m *Manager) onReceive(ch chan bool) {
if err := df.Decode(m.Tunnel); err != nil {
return
}
m.logger.Trace("dataframe<-tunnel: ", df)
switch df.Type {
case TypeRequest:
m.accept <- df