Skip to content

Commit

Permalink
adjust comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jul 27, 2024
1 parent 651dc4a commit 3040333
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion autotune.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type pulse struct {
seq uint32 // sequence of the signal
}

// autoTune object
// autoTune object to detect pulses in a signal
type autoTune struct {
pulses [maxAutoTuneSamples]pulse
}
Expand Down
1 change: 1 addition & 0 deletions batchconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
batchSize = 16
)

// batchConn defines the interface used in batch IO
type batchConn interface {
WriteBatch(ms []ipv4.Message, flags int) (int, error)
ReadBatch(ms []ipv4.Message, flags int) (int, error)
Expand Down
8 changes: 8 additions & 0 deletions crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import (
)

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

// loop unrolling to relieve data dependency
for i := 0; i < repeat; i++ {
s := src[base:][0:64]
d := dst[base:][0:64]
Expand Down Expand Up @@ -545,6 +551,8 @@ func decrypt16(block cipher.Block, dst, src, buf []byte) {
base := 0
repeat := n / 8
left := n % 8

// loop unrolling to relieve data dependency
for i := 0; i < repeat; i++ {
s := src[base:][0:128]
d := dst[base:][0:128]
Expand Down
2 changes: 2 additions & 0 deletions entropy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
)

// Entropy defines a entropy source
//
// Entropy in this file generate random bits for the first 16-bytes of each packets.
type Entropy interface {
Init()
Fill(nonce []byte)
Expand Down
1 change: 1 addition & 0 deletions fec.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (dec *fecDecoder) decode(in fecPacket) (recovered [][]byte) {
}
}

// if signal is out-of-sync, try to detect the pattern in the signal
if dec.shouldTune {
autoDS := dec.autoTune.FindPeriod(true)
autoPS := dec.autoTune.FindPeriod(false)
Expand Down
2 changes: 2 additions & 0 deletions readloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pkg/errors"
)

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

// defaultReadLoop is the standard procedure for reading and accepting connections on a listener
func (l *Listener) defaultMonitor() {
buf := make([]byte, mtuLimit)
for {
Expand Down
1 change: 0 additions & 1 deletion readloop_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// SOFTWARE.

//go:build !linux
// +build !linux

package kcp

Expand Down
4 changes: 2 additions & 2 deletions readloop_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"golang.org/x/net/ipv6"
)

// the read loop for a client session
// readLoop is the optimized version of readLoop for linux utilizing recvmmsg syscall
func (s *UDPSession) readLoop() {
// default version
if s.xconn == nil {
Expand Down Expand Up @@ -83,7 +83,7 @@ func (s *UDPSession) readLoop() {
}
}

// monitor incoming data for all connections of server
// monitor is the optimized version of monitor for linux utilizing recvmmsg syscall
func (l *Listener) monitor() {
var xconn batchConn
if _, ok := l.conn.(*net.UDPConn); ok {
Expand Down
2 changes: 2 additions & 0 deletions timedsched.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func NewTimedSched(parallel int) *TimedSched {
return ts
}

// sched is a goroutine to schedule and execute timed tasks.
func (ts *TimedSched) sched() {
var tasks timedFuncHeap
timer := time.NewTimer(0)
Expand Down Expand Up @@ -119,6 +120,7 @@ func (ts *TimedSched) sched() {
}
}

// prepend is the front desk goroutine to register tasks
func (ts *TimedSched) prepend() {
var tasks []timedFunc
for {
Expand Down
1 change: 1 addition & 0 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"golang.org/x/net/ipv4"
)

// defaultTx is the default procedure to transmit data
func (s *UDPSession) defaultTx(txqueue []ipv4.Message) {
nbytes := 0
npkts := 0
Expand Down
1 change: 0 additions & 1 deletion tx_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// SOFTWARE.

//go:build !linux
// +build !linux

package kcp

Expand Down
2 changes: 1 addition & 1 deletion tx_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// SOFTWARE.

//go:build linux
// +build linux

package kcp

Expand All @@ -34,6 +33,7 @@ import (
"golang.org/x/net/ipv4"
)

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

0 comments on commit 3040333

Please sign in to comment.