tcp context fixes
This commit is contained in:
parent
a0654b0016
commit
edfd5a9009
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
config.ini
|
||||
*.conf
|
||||
logs/
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/intellij+all,go
|
||||
|
16
tcp/flow.go
16
tcp/flow.go
@ -53,7 +53,7 @@ func NewFlow() Flow {
|
||||
}
|
||||
}
|
||||
|
||||
func NewFlowConn(conn Conn) Flow {
|
||||
func NewFlowConn(ctx context.Context, conn Conn) Flow {
|
||||
f := Flow{
|
||||
conn: conn,
|
||||
isAlive: true,
|
||||
@ -64,8 +64,8 @@ func NewFlowConn(conn Conn) Flow {
|
||||
produceErrors: make(chan error),
|
||||
}
|
||||
|
||||
go f.produceMarshalled()
|
||||
go f.consumeMarshalled()
|
||||
go f.produceMarshalled(ctx)
|
||||
go f.consumeMarshalled(ctx)
|
||||
|
||||
return f
|
||||
}
|
||||
@ -89,7 +89,7 @@ func InitiateFlow(local func() string, remote string) (*InitiatedFlow, error) {
|
||||
return &f, nil
|
||||
}
|
||||
|
||||
func (f *InitiatedFlow) Reconnect() error {
|
||||
func (f *InitiatedFlow) Reconnect(ctx context.Context) error {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
|
||||
@ -119,8 +119,8 @@ func (f *InitiatedFlow) Reconnect() error {
|
||||
f.conn = conn
|
||||
f.isAlive = true
|
||||
|
||||
go f.produceMarshalled()
|
||||
go f.consumeMarshalled()
|
||||
go f.produceMarshalled(ctx)
|
||||
go f.consumeMarshalled(ctx)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -191,7 +191,7 @@ func (f *Flow) Produce(ctx context.Context, v proxy.MacVerifier) (proxy.Packet,
|
||||
return proxy.SimplePacket(b), nil
|
||||
}
|
||||
|
||||
func (f *Flow) consumeMarshalled() {
|
||||
func (f *Flow) consumeMarshalled(ctx context.Context) {
|
||||
for {
|
||||
data := <-f.toConsume
|
||||
|
||||
@ -208,7 +208,7 @@ func (f *Flow) consumeMarshalled() {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Flow) produceMarshalled() {
|
||||
func (f *Flow) produceMarshalled(ctx context.Context) {
|
||||
buf := bufio.NewReader(f.conn)
|
||||
|
||||
for {
|
||||
|
@ -29,7 +29,7 @@ func NewListener(ctx context.Context, p *proxy.Proxy, local string, v func() pro
|
||||
panic(err)
|
||||
}
|
||||
|
||||
f := NewFlowConn(conn)
|
||||
f := NewFlowConn(ctx, conn)
|
||||
|
||||
log.Printf("received new tcp connection: %v\n", f)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user