recvDataFromRemote returns err

This commit is contained in:
Andy Wang 2019-08-16 23:47:15 +01:00
parent c276f504b5
commit 52796ad0b1
2 changed files with 10 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package multiplex
import ( import (
"errors" "errors"
"fmt"
"net" "net"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -136,12 +137,10 @@ func (sesh *Session) delStream(id uint32) {
sesh.streamsM.Unlock() sesh.streamsM.Unlock()
} }
func (sesh *Session) recvDataFromRemote(data []byte) { func (sesh *Session) recvDataFromRemote(data []byte) error {
frame, err := sesh.Deobfs(data) frame, err := sesh.Deobfs(data)
if err != nil { if err != nil {
// TODO: return this error return fmt.Errorf("Failed to decrypt a frame for session %v: %v", sesh.id, err)
log.Debugf("Failed to decrypt a frame for session %v: %v", sesh.id, err)
return
} }
sesh.streamsM.Lock() sesh.streamsM.Lock()
@ -149,10 +148,11 @@ func (sesh *Session) recvDataFromRemote(data []byte) {
stream, existing := sesh.streams[frame.StreamID] stream, existing := sesh.streams[frame.StreamID]
if existing { if existing {
stream.writeFrame(frame) stream.writeFrame(frame)
return nil
} else { } else {
if frame.Closing == 1 { if frame.Closing == 1 {
// If the stream has been closed and the current frame is a closing frame, we do noop // If the stream has been closed and the current frame is a closing frame, we do noop
return return nil
} else { } else {
// it may be tempting to use the connId from which the frame was received. However it doesn't make // it may be tempting to use the connId from which the frame was received. However it doesn't make
// any difference because we only care to send the data from the same stream through the same // any difference because we only care to send the data from the same stream through the same
@ -164,7 +164,7 @@ func (sesh *Session) recvDataFromRemote(data []byte) {
sesh.streams[frame.StreamID] = stream sesh.streams[frame.StreamID] = stream
sesh.acceptCh <- stream sesh.acceptCh <- stream
stream.writeFrame(frame) stream.writeFrame(frame)
return return nil
} }
} }

View File

@ -149,6 +149,9 @@ func (sb *switchboard) deplex(connId uint32, conn net.Conn) {
return return
} }
sb.session.recvDataFromRemote(buf[:n]) err = sb.session.recvDataFromRemote(buf[:n])
if err != nil {
log.Error(err)
}
} }
} }