Remove redundant functions

This commit is contained in:
Qian Wang 2018-12-31 11:30:39 +00:00
parent c09fc86c58
commit f3f3042c81
4 changed files with 9 additions and 39 deletions

View File

@ -114,6 +114,7 @@ func (s *Stream) recvNewFrame() {
func (s *Stream) pushFrame(f *Frame) {
if f.Closing == 1 {
// empty data indicates closing signal
s.sortedBufCh <- []byte{}
return
}

View File

@ -94,16 +94,8 @@ func (sesh *Session) delStream(id uint32) {
sesh.streamsM.Unlock()
}
func (sesh *Session) isStream(id uint32) bool {
sesh.streamsM.RLock()
_, ok := sesh.streams[id]
sesh.streamsM.RUnlock()
return ok
}
// If the stream has been closed and the triggering frame is a closing frame,
// we return nil
func (sesh *Session) getOrAddStream(id uint32, closingFrame bool) *Stream {
// either fetch an existing stream or instantiate a new stream and put it in the dict, and return it
func (sesh *Session) getStream(id uint32, closingFrame bool) *Stream {
// it would have been neater to use defer Unlock(), however it gives
// non-negligable overhead and this function is performance critical
sesh.streamsM.Lock()
@ -113,6 +105,8 @@ func (sesh *Session) getOrAddStream(id uint32, closingFrame bool) *Stream {
return stream
} else {
if closingFrame {
// If the stream has been closed and the current frame is a closing frame,
// we return nil
sesh.streamsM.Unlock()
return nil
} else {
@ -126,24 +120,6 @@ func (sesh *Session) getOrAddStream(id uint32, closingFrame bool) *Stream {
}
}
func (sesh *Session) getStream(id uint32) *Stream {
sesh.streamsM.RLock()
ret := sesh.streams[id]
sesh.streamsM.RUnlock()
return ret
}
// addStream is used when the remote opened a new stream and we got notified
func (sesh *Session) addStream(id uint32) *Stream {
stream := makeStream(id, sesh)
sesh.streamsM.Lock()
sesh.streams[id] = stream
sesh.streamsM.Unlock()
sesh.acceptCh <- stream
log.Printf("Adding stream %v\n", id)
return stream
}
func (sesh *Session) Close() error {
// Because closing a closed channel causes panic
sesh.suicide.Do(func() { close(sesh.die) })
@ -153,13 +129,12 @@ func (sesh *Session) Close() error {
// because stream.Close calls sesh.delStream, which locks the mutex.
// so we need to implement a method of stream that closes the stream without calling
// sesh.delStream
// This can also be seen in smux
go stream.closeNoDelMap()
delete(sesh.streams, id)
}
sesh.streamsM.Unlock()
sesh.sb.shutdown()
sesh.sb.closeAll()
return nil
}

View File

@ -129,14 +129,14 @@ func (sb *switchboard) removeConn(closing *connEnclave) {
}
// actively triggered by session.Close()
func (sb *switchboard) shutdown() {
func (sb *switchboard) closeAll() {
for _, ce := range sb.ces {
ce.remoteConn.Close()
}
}
// deplex function costantly reads from a TCP connection, call deobfs and distribute it
// to the corresponding frame
// to the corresponding stream
func (sb *switchboard) deplex(ce *connEnclave) {
buf := make([]byte, 20480)
for {
@ -170,7 +170,7 @@ func (sb *switchboard) deplex(ce *connEnclave) {
// of the library. Maybe there's a race somewhere? I may eventually use another
// method to encrypt the headers. xxHash isn't cryptographic afterall.
stream := sb.session.getOrAddStream(frame.StreamID, frame.Closing == 1)
stream := sb.session.getStream(frame.StreamID, frame.Closing == 1)
// if the frame is telling us to close a closed stream
// (this happens when ss-server and ss-local closes the stream
// simutaneously), we don't do anything

View File

@ -67,12 +67,6 @@ func (u *User) updateInfo(uinfo UserInfo) {
u.setExpiryTime(uinfo.ExpiryTime)
}
func (u *User) PutSession(sessionID uint32, sesh *mux.Session) {
u.sessionsM.Lock()
u.sessions[sessionID] = sesh
u.sessionsM.Unlock()
}
func (u *User) DelSession(sessionID uint32) {
u.sessionsM.Lock()
delete(u.sessions, sessionID)