Created
October 29, 2019 13:50
-
-
Save zckevin/5a54d633ce5ae937462622e97de52511 to your computer and use it in GitHub Desktop.
wtf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Session struct { | |
Conns []net.Conn | |
} | |
packet | |
timeout timer | |
history | |
onTimeout | |
// ? find another conn(not in history) | |
// update history | |
// insert into retran list | |
insert into sideTrans q | |
Bytes() | |
session | |
sideTrans queue | |
send packetList | |
mutex | |
recv packetList | |
mutex | |
Read | |
iterate recv packetList and remove nodes until visiting hole | |
Write() | |
pack []byte to packet | |
append to send packetList tail | |
getTask() | |
while n < wnd | |
if conn.id in pkt.history | |
continue | |
// iter retran list until empty | |
iter sideTrans q until empty | |
iter send list until empty | |
sendTimes -= 1 | |
if sendTimes == 0: | |
remove pkt node | |
readLoop() | |
pkt := <-sess.readCh | |
switch pkt.typ { | |
case data: | |
insert into recv packetList by seq number | |
if seq < head seq | |
return | |
else | |
? ack | |
ackloop.ch <- ack | |
update session.ratings | |
case ping: | |
pong | |
case ack: | |
} | |
ackloop() | |
ackBlock | |
for { | |
select { | |
case ack := <-ackloop.ch: | |
add to ackBlock | |
case <-ticker.C: | |
if ackBlock != nil { | |
pkt := ackBlock.toPacket() | |
insert pkt into sideTrans | |
ackBlock = nil | |
} | |
} | |
} | |
Close | |
addConn | |
conn | |
id | |
close() | |
readLoop() | |
read until full packet, could block | |
session.readCh <- pkt, could block | |
writeLoop() | |
wnd = conn.getWnd() | |
session.getTask(wnd), could block | |
for range pkts, conn.Write(pkt.Bytes()) | |
server | |
serveSession | |
client | |
dialSession |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment