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

@ -420,16 +420,16 @@ func (this *Connection) Input(data []byte) int {
switch seg := seg.(type) { switch seg := seg.(type) {
case *DataSegment: case *DataSegment:
this.HandleOption(seg.Opt) this.HandleOption(seg.Option)
this.receivingWorker.ProcessSegment(seg) this.receivingWorker.ProcessSegment(seg)
this.dataInputCond.Signal() this.dataInputCond.Signal()
case *AckSegment: case *AckSegment:
this.HandleOption(seg.Opt) this.HandleOption(seg.Option)
this.sendingWorker.ProcessSegment(current, seg) this.sendingWorker.ProcessSegment(current, seg)
this.dataOutputCond.Signal() this.dataOutputCond.Signal()
case *CmdOnlySegment: case *CmdOnlySegment:
this.HandleOption(seg.Opt) this.HandleOption(seg.Option)
if seg.Cmd == CommandTerminate { if seg.Command == 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 = CommandTerminate seg.Command = CommandTerminate
this.output.Write(seg) this.output.Write(seg)
this.output.Flush() this.output.Flush()
@ -493,11 +493,11 @@ 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 = CommandPing seg.Command = 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 {
seg.Opt = SegmentOptionClose seg.Option = SegmentOptionClose
} }
this.output.Write(seg) this.output.Write(seg)
this.lastPingTime = current this.lastPingTime = current

@ -253,7 +253,7 @@ func (this *ReceivingWorker) Write(seg Segment) {
ackSeg.ReceivingNext = this.nextNumber ackSeg.ReceivingNext = this.nextNumber
ackSeg.ReceivingWindow = this.nextNumber + this.windowSize ackSeg.ReceivingWindow = this.nextNumber + this.windowSize
if this.conn.state == StateReadyToClose { if this.conn.state == StateReadyToClose {
ackSeg.Opt = SegmentOptionClose ackSeg.Option = SegmentOptionClose
} }
this.conn.output.Write(ackSeg) this.conn.output.Write(ackSeg)
this.updated = false this.updated = false

@ -34,7 +34,7 @@ const (
type DataSegment struct { type DataSegment struct {
Conv uint16 Conv uint16
Opt SegmentOption Option SegmentOption
Timestamp uint32 Timestamp uint32
Number uint32 Number uint32
SendingNext uint32 SendingNext uint32
@ -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(CommandData), byte(this.Opt)) b = append(b, byte(CommandData), byte(this.Option))
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)
@ -71,7 +71,7 @@ func (this *DataSegment) Release() {
type AckSegment struct { type AckSegment struct {
Conv uint16 Conv uint16
Opt SegmentOption Option SegmentOption
ReceivingWindow uint32 ReceivingWindow uint32
ReceivingNext uint32 ReceivingNext uint32
Count byte Count byte
@ -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(CommandACK), byte(this.Opt)) b = append(b, byte(CommandACK), byte(this.Option))
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,8 +117,8 @@ func (this *AckSegment) Release() {
type CmdOnlySegment struct { type CmdOnlySegment struct {
Conv uint16 Conv uint16
Cmd Command Command Command
Opt SegmentOption Option SegmentOption
SendingNext uint32 SendingNext uint32
ReceivinNext uint32 ReceivinNext uint32
} }
@ -133,7 +133,7 @@ func (this *CmdOnlySegment) ByteSize() int {
func (this *CmdOnlySegment) Bytes(b []byte) []byte { func (this *CmdOnlySegment) Bytes(b []byte) []byte {
b = serial.Uint16ToBytes(this.Conv, b) b = serial.Uint16ToBytes(this.Conv, b)
b = append(b, byte(this.Cmd), byte(this.Opt)) b = append(b, byte(this.Command), byte(this.Option))
b = serial.Uint32ToBytes(this.SendingNext, b) b = serial.Uint32ToBytes(this.SendingNext, b)
b = serial.Uint32ToBytes(this.ReceivinNext, b) b = serial.Uint32ToBytes(this.ReceivinNext, b)
return b return b
@ -157,7 +157,7 @@ func ReadSegment(buf []byte) (Segment, []byte) {
if cmd == CommandData { if cmd == CommandData {
seg := NewDataSegment() seg := NewDataSegment()
seg.Conv = conv seg.Conv = conv
seg.Opt = opt seg.Option = opt
if len(buf) < 16 { if len(buf) < 16 {
return nil, nil return nil, nil
} }
@ -185,7 +185,7 @@ func ReadSegment(buf []byte) (Segment, []byte) {
if cmd == CommandACK { if cmd == CommandACK {
seg := NewAckSegment() seg := NewAckSegment()
seg.Conv = conv seg.Conv = conv
seg.Opt = opt seg.Option = opt
if len(buf) < 9 { if len(buf) < 9 {
return nil, nil return nil, nil
} }
@ -212,8 +212,8 @@ func ReadSegment(buf []byte) (Segment, []byte) {
seg := NewCmdOnlySegment() seg := NewCmdOnlySegment()
seg.Conv = conv seg.Conv = conv
seg.Cmd = cmd seg.Command = cmd
seg.Opt = opt seg.Option = opt
if len(buf) < 8 { if len(buf) < 8 {
return nil, nil return nil, nil

@ -356,9 +356,9 @@ func (this *SendingWorker) Write(seg Segment) {
dataSeg.Conv = this.conn.conv dataSeg.Conv = this.conn.conv
dataSeg.SendingNext = this.firstUnacknowledged dataSeg.SendingNext = this.firstUnacknowledged
dataSeg.Opt = 0 dataSeg.Option = 0
if this.conn.State() == StateReadyToClose { if this.conn.State() == StateReadyToClose {
dataSeg.Opt = SegmentOptionClose dataSeg.Option = SegmentOptionClose
} }
this.conn.output.Write(dataSeg) this.conn.output.Write(dataSeg)

Loading…
Cancel
Save