| 88 | } |
| 89 | |
| 90 | func MakeSession(id uint32, config SessionConfig) *Session { |
| 91 | sesh := &Session{ |
| 92 | id: id, |
| 93 | SessionConfig: config, |
| 94 | nextStreamID: 1, |
| 95 | acceptCh: make(chan *Stream, acceptBacklog), |
| 96 | recvFramePool: sync.Pool{New: func() interface{} { return &Frame{} }}, |
| 97 | streams: map[uint32]*Stream{}, |
| 98 | } |
| 99 | sesh.addrs.Store([]net.Addr{nil, nil}) |
| 100 | |
| 101 | if config.Valve == nil { |
| 102 | sesh.Valve = UNLIMITED_VALVE |
| 103 | } |
| 104 | if config.MsgOnWireSizeLimit <= 0 { |
| 105 | sesh.MsgOnWireSizeLimit = defaultMaxOnWireSize |
| 106 | } |
| 107 | if config.InactivityTimeout == 0 { |
| 108 | sesh.InactivityTimeout = defaultInactivityTimeout |
| 109 | } |
| 110 | |
| 111 | sesh.maxStreamUnitWrite = sesh.MsgOnWireSizeLimit - frameHeaderLength - maxExtraLen |
| 112 | sesh.streamSendBufferSize = sesh.MsgOnWireSizeLimit |
| 113 | sesh.connReceiveBufferSize = 20480 // for backwards compatibility |
| 114 | |
| 115 | sesh.streamObfsBufPool = sync.Pool{New: func() interface{} { |
| 116 | b := make([]byte, sesh.streamSendBufferSize) |
| 117 | return &b |
| 118 | }} |
| 119 | |
| 120 | sesh.sb = makeSwitchboard(sesh) |
| 121 | time.AfterFunc(sesh.InactivityTimeout, sesh.checkTimeout) |
| 122 | return sesh |
| 123 | } |
| 124 | |
| 125 | func (sesh *Session) GetSessionKey() [32]byte { |
| 126 | return sesh.sessionKey |