Improve comments

pull/132/head
Andy Wang 4 years ago
parent 977f51ce48
commit 651854904f

@ -133,7 +133,7 @@ func MakeObfs(salsaKey [32]byte, payloadCipher cipher.AEAD) Obfser {
// containing the message to be decrypted, and returns a *Frame containing the frame // containing the message to be decrypted, and returns a *Frame containing the frame
// information and plaintext // information and plaintext
func MakeDeobfs(salsaKey [32]byte, payloadCipher cipher.AEAD) Deobfser { func MakeDeobfs(salsaKey [32]byte, payloadCipher cipher.AEAD) Deobfser {
// stream header length + minimum data size (i.e. nonce size of salsa20) // frame header length + minimum data size (i.e. nonce size of salsa20)
const minInputLen = HEADER_LEN + salsa20NonceSize const minInputLen = HEADER_LEN + salsa20NonceSize
deobfs := func(in []byte) (*Frame, error) { deobfs := func(in []byte) (*Frame, error) {
if len(in) < minInputLen { if len(in) < minInputLen {

@ -29,10 +29,12 @@ type switchboardStrategy int
type SessionConfig struct { type SessionConfig struct {
Obfuscator Obfuscator
// Valve is used to limit transmission rates, and record and limit usage
Valve Valve
Unordered bool Unordered bool
// A Singleplexing session always has just one stream
Singleplex bool Singleplex bool
// maximum size of an obfuscated frame, including headers and overhead // maximum size of an obfuscated frame, including headers and overhead
@ -48,6 +50,8 @@ type SessionConfig struct {
InactivityTimeout time.Duration InactivityTimeout time.Duration
} }
// A Session represents a self-contained communication chain between local and remote. It manages its streams and sent
// and receive data using the connection pool filled with connections added to the session.
type Session struct { type Session struct {
id uint32 id uint32
@ -120,12 +124,14 @@ func (sesh *Session) streamCount() uint32 {
return atomic.LoadUint32(&sesh.activeStreamCount) return atomic.LoadUint32(&sesh.activeStreamCount)
} }
// AddConnection is used to add an underlying connection to the connection pool
func (sesh *Session) AddConnection(conn net.Conn) { func (sesh *Session) AddConnection(conn net.Conn) {
sesh.sb.addConn(conn) sesh.sb.addConn(conn)
addrs := []net.Addr{conn.LocalAddr(), conn.RemoteAddr()} addrs := []net.Addr{conn.LocalAddr(), conn.RemoteAddr()}
sesh.addrs.Store(addrs) sesh.addrs.Store(addrs)
} }
// OpenStream is similar to net.Dial. It opens up a new stream
func (sesh *Session) OpenStream() (*Stream, error) { func (sesh *Session) OpenStream() (*Stream, error) {
if sesh.IsClosed() { if sesh.IsClosed() {
return nil, ErrBrokenSession return nil, ErrBrokenSession
@ -144,6 +150,7 @@ func (sesh *Session) OpenStream() (*Stream, error) {
return stream, nil return stream, nil
} }
// Accept is similar to net.Listener's Accept(). It blocks and returns an incoming stream
func (sesh *Session) Accept() (net.Conn, error) { func (sesh *Session) Accept() (net.Conn, error) {
if sesh.IsClosed() { if sesh.IsClosed() {
return nil, ErrBrokenSession return nil, ErrBrokenSession

Loading…
Cancel
Save