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) {
case *DataSegment:
this.HandleOption(seg.Opt)
this.HandleOption(seg.Option)
this.receivingWorker.ProcessSegment(seg)
this.dataInputCond.Signal()
case *AckSegment:
this.HandleOption(seg.Opt)
this.HandleOption(seg.Option)
this.sendingWorker.ProcessSegment(current, seg)
this.dataOutputCond.Signal()
case *CmdOnlySegment:
this.HandleOption(seg.Opt)
if seg.Cmd == CommandTerminate {
this.HandleOption(seg.Option)
if seg.Command == 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 = CommandTerminate
seg.Command = CommandTerminate
this.output.Write(seg)
this.output.Flush()
@ -493,11 +493,11 @@ 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 = CommandPing
seg.Command = CommandPing
seg.ReceivinNext = this.receivingWorker.nextNumber
seg.SendingNext = this.sendingWorker.firstUnacknowledged
if this.State() == StateReadyToClose {
seg.Opt = SegmentOptionClose
seg.Option = SegmentOptionClose
}
this.output.Write(seg)
this.lastPingTime = current

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

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

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

Loading…
Cancel
Save