rename command

pull/215/head
v2ray 8 years ago
parent ffdce592ec
commit ef2d49302d
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -429,7 +429,7 @@ func (this *Connection) Input(data []byte) int {
this.dataOutputCond.Signal() this.dataOutputCond.Signal()
case *CmdOnlySegment: case *CmdOnlySegment:
this.HandleOption(seg.Opt) this.HandleOption(seg.Opt)
if seg.Cmd == SegmentCommandTerminated { if seg.Cmd == CommandTerminate {
state := this.State() state := this.State()
if state == StateActive || if state == StateActive ||
state == StatePeerClosed { state == StatePeerClosed {
@ -469,7 +469,7 @@ func (this *Connection) flush() {
defer seg.Release() defer seg.Release()
seg.Conv = this.conv seg.Conv = this.conv
seg.Cmd = SegmentCommandTerminated seg.Cmd = CommandTerminate
this.output.Write(seg) this.output.Write(seg)
this.output.Flush() this.output.Flush()
@ -493,7 +493,7 @@ func (this *Connection) flush() {
if this.sendingWorker.PingNecessary() || this.receivingWorker.PingNecessary() || current-atomic.LoadUint32(&this.lastPingTime) >= 5000 { if this.sendingWorker.PingNecessary() || this.receivingWorker.PingNecessary() || current-atomic.LoadUint32(&this.lastPingTime) >= 5000 {
seg := NewCmdOnlySegment() seg := NewCmdOnlySegment()
seg.Conv = this.conv seg.Conv = this.conv
seg.Cmd = SegmentCommandPing seg.Cmd = CommandPing
seg.ReceivinNext = this.receivingWorker.nextNumber seg.ReceivinNext = this.receivingWorker.nextNumber
seg.SendingNext = this.sendingWorker.firstUnacknowledged seg.SendingNext = this.sendingWorker.firstUnacknowledged
if this.State() == StateReadyToClose { if this.State() == StateReadyToClose {

@ -63,11 +63,11 @@ func (this *Listener) OnReceive(payload *alloc.Buffer, src v2net.Destination) {
return return
} }
conv := serial.BytesToUint16(payload.Value) conv := serial.BytesToUint16(payload.Value)
cmd := SegmentCommand(payload.Value[2]) cmd := Command(payload.Value[2])
sourceId := src.NetAddr() + "|" + serial.Uint16ToString(conv) sourceId := src.NetAddr() + "|" + serial.Uint16ToString(conv)
conn, found := this.sessions[sourceId] conn, found := this.sessions[sourceId]
if !found { if !found {
if cmd == SegmentCommandTerminated { if cmd == CommandTerminate {
return return
} }
log.Debug("KCP|Listener: Creating session with id(", sourceId, ") from ", src) log.Debug("KCP|Listener: Creating session with id(", sourceId, ") from ", src)

@ -7,13 +7,13 @@ import (
"github.com/v2ray/v2ray-core/common/serial" "github.com/v2ray/v2ray-core/common/serial"
) )
type SegmentCommand byte type Command byte
const ( const (
SegmentCommandACK SegmentCommand = 0 CommandACK Command = 0
SegmentCommandData SegmentCommand = 1 CommandData Command = 1
SegmentCommandTerminated SegmentCommand = 2 CommandTerminate Command = 2
SegmentCommandPing SegmentCommand = 3 CommandPing Command = 3
) )
type SegmentOption byte type SegmentOption byte
@ -51,7 +51,7 @@ func NewDataSegment() *DataSegment {
func (this *DataSegment) Bytes(b []byte) []byte { func (this *DataSegment) Bytes(b []byte) []byte {
b = serial.Uint16ToBytes(this.Conv, b) 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.Timestamp, b)
b = serial.Uint32ToBytes(this.Number, b) b = serial.Uint32ToBytes(this.Number, b)
b = serial.Uint32ToBytes(this.SendingNext, b) b = serial.Uint32ToBytes(this.SendingNext, b)
@ -99,7 +99,7 @@ func (this *AckSegment) ByteSize() int {
func (this *AckSegment) Bytes(b []byte) []byte { func (this *AckSegment) Bytes(b []byte) []byte {
b = serial.Uint16ToBytes(this.Conv, b) 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.ReceivingWindow, b)
b = serial.Uint32ToBytes(this.ReceivingNext, b) b = serial.Uint32ToBytes(this.ReceivingNext, b)
b = append(b, this.Count) b = append(b, this.Count)
@ -117,7 +117,7 @@ func (this *AckSegment) Release() {
type CmdOnlySegment struct { type CmdOnlySegment struct {
Conv uint16 Conv uint16
Cmd SegmentCommand Cmd Command
Opt SegmentOption Opt SegmentOption
SendingNext uint32 SendingNext uint32
ReceivinNext uint32 ReceivinNext uint32
@ -150,11 +150,11 @@ func ReadSegment(buf []byte) (Segment, []byte) {
conv := serial.BytesToUint16(buf) conv := serial.BytesToUint16(buf)
buf = buf[2:] buf = buf[2:]
cmd := SegmentCommand(buf[0]) cmd := Command(buf[0])
opt := SegmentOption(buf[1]) opt := SegmentOption(buf[1])
buf = buf[2:] buf = buf[2:]
if cmd == SegmentCommandData { if cmd == CommandData {
seg := NewDataSegment() seg := NewDataSegment()
seg.Conv = conv seg.Conv = conv
seg.Opt = opt seg.Opt = opt
@ -182,7 +182,7 @@ func ReadSegment(buf []byte) (Segment, []byte) {
return seg, buf return seg, buf
} }
if cmd == SegmentCommandACK { if cmd == CommandACK {
seg := NewAckSegment() seg := NewAckSegment()
seg.Conv = conv seg.Conv = conv
seg.Opt = opt seg.Opt = opt

Loading…
Cancel
Save