Skip to content

Commit 3040333

Browse files
committed
adjust comments
1 parent 651dc4a commit 3040333

12 files changed

+21
-6
lines changed

autotune.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type pulse struct {
3030
seq uint32 // sequence of the signal
3131
}
3232

33-
// autoTune object
33+
// autoTune object to detect pulses in a signal
3434
type autoTune struct {
3535
pulses [maxAutoTuneSamples]pulse
3636
}

batchconn.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
batchSize = 16
2929
)
3030

31+
// batchConn defines the interface used in batch IO
3132
type batchConn interface {
3233
WriteBatch(ms []ipv4.Message, flags int) (int, error)
3334
ReadBatch(ms []ipv4.Message, flags int) (int, error)

crypt.go

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ import (
4242
)
4343

4444
var (
45+
// a defined initial vector
46+
// https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Initialization_vector_.28IV.29
47+
// https://en.wikipedia.org/wiki/Initialization_vector
48+
// actually initial vector is not used in this package, we prepend a random nonce to each outgoing packets.
49+
// though IV is fixed, the first 8 bytes of the encrypted data is always random.
4550
initialVector = []byte{167, 115, 79, 156, 18, 172, 27, 1, 164, 21, 242, 193, 252, 120, 230, 107}
4651
saltxor = `sH3CIVoF#rWLtJo6`
4752
)
@@ -459,6 +464,7 @@ func decrypt8(block cipher.Block, dst, src, buf []byte) {
459464
ptr_tbl := (*uint64)(unsafe.Pointer(&tbl[0]))
460465
ptr_next := (*uint64)(unsafe.Pointer(&next[0]))
461466

467+
// loop unrolling to relieve data dependency
462468
for i := 0; i < repeat; i++ {
463469
s := src[base:][0:64]
464470
d := dst[base:][0:64]
@@ -545,6 +551,8 @@ func decrypt16(block cipher.Block, dst, src, buf []byte) {
545551
base := 0
546552
repeat := n / 8
547553
left := n % 8
554+
555+
// loop unrolling to relieve data dependency
548556
for i := 0; i < repeat; i++ {
549557
s := src[base:][0:128]
550558
d := dst[base:][0:128]

entropy.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
)
3232

3333
// Entropy defines a entropy source
34+
//
35+
// Entropy in this file generate random bits for the first 16-bytes of each packets.
3436
type Entropy interface {
3537
Init()
3638
Fill(nonce []byte)

fec.go

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (dec *fecDecoder) decode(in fecPacket) (recovered [][]byte) {
112112
}
113113
}
114114

115+
// if signal is out-of-sync, try to detect the pattern in the signal
115116
if dec.shouldTune {
116117
autoDS := dec.autoTune.FindPeriod(true)
117118
autoPS := dec.autoTune.FindPeriod(false)

readloop.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/pkg/errors"
2929
)
3030

31+
// defaultReadLoop is the standard procedure for reading from a connection
3132
func (s *UDPSession) defaultReadLoop() {
3233
buf := make([]byte, mtuLimit)
3334
var src string
@@ -48,6 +49,7 @@ func (s *UDPSession) defaultReadLoop() {
4849
}
4950
}
5051

52+
// defaultReadLoop is the standard procedure for reading and accepting connections on a listener
5153
func (l *Listener) defaultMonitor() {
5254
buf := make([]byte, mtuLimit)
5355
for {

readloop_generic.go

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// SOFTWARE.
2222

2323
//go:build !linux
24-
// +build !linux
2524

2625
package kcp
2726

readloop_linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"golang.org/x/net/ipv6"
3636
)
3737

38-
// the read loop for a client session
38+
// readLoop is the optimized version of readLoop for linux utilizing recvmmsg syscall
3939
func (s *UDPSession) readLoop() {
4040
// default version
4141
if s.xconn == nil {
@@ -83,7 +83,7 @@ func (s *UDPSession) readLoop() {
8383
}
8484
}
8585

86-
// monitor incoming data for all connections of server
86+
// monitor is the optimized version of monitor for linux utilizing recvmmsg syscall
8787
func (l *Listener) monitor() {
8888
var xconn batchConn
8989
if _, ok := l.conn.(*net.UDPConn); ok {

timedsched.go

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func NewTimedSched(parallel int) *TimedSched {
8181
return ts
8282
}
8383

84+
// sched is a goroutine to schedule and execute timed tasks.
8485
func (ts *TimedSched) sched() {
8586
var tasks timedFuncHeap
8687
timer := time.NewTimer(0)
@@ -119,6 +120,7 @@ func (ts *TimedSched) sched() {
119120
}
120121
}
121122

123+
// prepend is the front desk goroutine to register tasks
122124
func (ts *TimedSched) prepend() {
123125
var tasks []timedFunc
124126
for {

tx.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"golang.org/x/net/ipv4"
3030
)
3131

32+
// defaultTx is the default procedure to transmit data
3233
func (s *UDPSession) defaultTx(txqueue []ipv4.Message) {
3334
nbytes := 0
3435
npkts := 0

tx_generic.go

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// SOFTWARE.
2222

2323
//go:build !linux
24-
// +build !linux
2524

2625
package kcp
2726

tx_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
// SOFTWARE.
2222

2323
//go:build linux
24-
// +build linux
2524

2625
package kcp
2726

@@ -34,6 +33,7 @@ import (
3433
"golang.org/x/net/ipv4"
3534
)
3635

36+
// tx is the optimized procedure to transmit packets utilizing the linux sendmmsg system call
3737
func (s *UDPSession) tx(txqueue []ipv4.Message) {
3838
// default version
3939
if s.xconn == nil || s.xconnWriteError != nil {

0 commit comments

Comments
 (0)