diff --git a/transport/internet/kcp/connection.go b/transport/internet/kcp/connection.go index 209a282af..6f2f77966 100644 --- a/transport/internet/kcp/connection.go +++ b/transport/internet/kcp/connection.go @@ -429,7 +429,7 @@ func (this *Connection) Input(data []byte) int { this.dataOutputCond.Signal() case *CmdOnlySegment: this.HandleOption(seg.Opt) - if seg.Cmd == SegmentCommandTerminated { + if seg.Cmd == CommandTerminate { state := this.State() if state == StateActive || state == StatePeerClosed { @@ -469,7 +469,7 @@ func (this *Connection) flush() { defer seg.Release() seg.Conv = this.conv - seg.Cmd = SegmentCommandTerminated + seg.Cmd = CommandTerminate this.output.Write(seg) this.output.Flush() @@ -493,7 +493,7 @@ func (this *Connection) flush() { if this.sendingWorker.PingNecessary() || this.receivingWorker.PingNecessary() || current-atomic.LoadUint32(&this.lastPingTime) >= 5000 { seg := NewCmdOnlySegment() seg.Conv = this.conv - seg.Cmd = SegmentCommandPing + seg.Cmd = CommandPing seg.ReceivinNext = this.receivingWorker.nextNumber seg.SendingNext = this.sendingWorker.firstUnacknowledged if this.State() == StateReadyToClose { diff --git a/transport/internet/kcp/listener.go b/transport/internet/kcp/listener.go index c95cda534..1f82ca6fb 100644 --- a/transport/internet/kcp/listener.go +++ b/transport/internet/kcp/listener.go @@ -63,11 +63,11 @@ func (this *Listener) OnReceive(payload *alloc.Buffer, src v2net.Destination) { return } conv := serial.BytesToUint16(payload.Value) - cmd := SegmentCommand(payload.Value[2]) + cmd := Command(payload.Value[2]) sourceId := src.NetAddr() + "|" + serial.Uint16ToString(conv) conn, found := this.sessions[sourceId] if !found { - if cmd == SegmentCommandTerminated { + if cmd == CommandTerminate { return } log.Debug("KCP|Listener: Creating session with id(", sourceId, ") from ", src) diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index c20c66877..1c8c739eb 100644 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -7,13 +7,13 @@ import ( "github.com/v2ray/v2ray-core/common/serial" ) -type SegmentCommand byte +type Command byte const ( - SegmentCommandACK SegmentCommand = 0 - SegmentCommandData SegmentCommand = 1 - SegmentCommandTerminated SegmentCommand = 2 - SegmentCommandPing SegmentCommand = 3 + CommandACK Command = 0 + CommandData Command = 1 + CommandTerminate Command = 2 + CommandPing Command = 3 ) type SegmentOption byte @@ -51,7 +51,7 @@ func NewDataSegment() *DataSegment { func (this *DataSegment) Bytes(b []byte) []byte { b = serial.Uint16ToBytes(this.Conv, b) - b = append(b, byte(SegmentCommandData), byte(this.Opt)) + b = append(b, byte(CommandData), byte(this.Opt)) b = serial.Uint32ToBytes(this.Timestamp, b) b = serial.Uint32ToBytes(this.Number, b) b = serial.Uint32ToBytes(this.SendingNext, b) @@ -99,7 +99,7 @@ func (this *AckSegment) ByteSize() int { func (this *AckSegment) Bytes(b []byte) []byte { b = serial.Uint16ToBytes(this.Conv, b) - b = append(b, byte(SegmentCommandACK), byte(this.Opt)) + b = append(b, byte(CommandACK), byte(this.Opt)) b = serial.Uint32ToBytes(this.ReceivingWindow, b) b = serial.Uint32ToBytes(this.ReceivingNext, b) b = append(b, this.Count) @@ -117,7 +117,7 @@ func (this *AckSegment) Release() { type CmdOnlySegment struct { Conv uint16 - Cmd SegmentCommand + Cmd Command Opt SegmentOption SendingNext uint32 ReceivinNext uint32 @@ -150,11 +150,11 @@ func ReadSegment(buf []byte) (Segment, []byte) { conv := serial.BytesToUint16(buf) buf = buf[2:] - cmd := SegmentCommand(buf[0]) + cmd := Command(buf[0]) opt := SegmentOption(buf[1]) buf = buf[2:] - if cmd == SegmentCommandData { + if cmd == CommandData { seg := NewDataSegment() seg.Conv = conv seg.Opt = opt @@ -182,7 +182,7 @@ func ReadSegment(buf []byte) (Segment, []byte) { return seg, buf } - if cmd == SegmentCommandACK { + if cmd == CommandACK { seg := NewAckSegment() seg.Conv = conv seg.Opt = opt