Skip to content

Commit

Permalink
[]Option -> []*Option
Browse files Browse the repository at this point in the history
  • Loading branch information
Petar Maymounkov committed Jun 15, 2011
1 parent e809a52 commit 81411c4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 26 deletions.
1 change: 0 additions & 1 deletion dccp/REMARK
@@ -1,5 +1,4 @@

* []Option -> []*Option
* CCID-inspired Reset and Reset-code separation b/w Sender/receiver

* use cc only in OPEN and PARTOPEN states
Expand Down
8 changes: 4 additions & 4 deletions dccp/cc.go
Expand Up @@ -54,14 +54,14 @@ type SenderCongestionControl interface {

// Conn calls OnWrite before a packet is sent to give CongestionControl
// an opportunity to add CCVal and options to an outgoing packet
OnWrite(htype byte, x bool, seqno int64) (ccval byte, options []Option)
OnWrite(htype byte, x bool, seqno int64) (ccval byte, options []*Option)

// Conn calls OnRead after a packet has been accepted an validated
// If OnRead returns ErrDrop, the packet will be dropped and no further processing
// will occur. If if it returns ErrReset, the connection will be reset.
// TODO: ErrReset behavior is not implemented. ErrReset should wrap the Reset Code to be
// used.
OnRead(htype byte, x bool, seqno int64, options []Option) os.Error
OnRead(htype byte, x bool, seqno int64, options []*Option) os.Error

// Strobe blocks until a new packet can be sent without violating the
// congestion control rate limit
Expand All @@ -88,14 +88,14 @@ type ReceiverCongestionControl interface {

// Conn calls OnWrite before a packet is sent to give CongestionControl
// an opportunity to add CCVal and options to an outgoing packet
OnWrite(htype byte, x bool, seqno int64) (options []Option)
OnWrite(htype byte, x bool, seqno int64) (options []*Option)

// Conn calls OnRead after a packet has been accepted and validated
// If OnRead returns ErrDrop, the packet will be dropped and no further processing
// will occur. If if it returns ErrReset, the connection will be reset.
// TODO: ErrReset behavior is not implemented. ErrReset should wrap the Reset Code to be
// used.
OnRead(htype byte, x bool, seqno int64, ccval byte, options []Option) os.Error
OnRead(htype byte, x bool, seqno int64, ccval byte, options []*Option) os.Error

// ??

Expand Down
8 changes: 4 additions & 4 deletions dccp/ccfixed.go
Expand Up @@ -62,9 +62,9 @@ func (scc *fixedRateSenderControl) GetCCMPS() int32 { return 1e9 }

func (scc *fixedRateSenderControl) GetRTT() int64 { return RTT_DEFAULT }

func (scc *fixedRateSenderControl) OnWrite(htype byte, x bool, seqno int64) (ccval byte, options []Option) { return 0, nil }
func (scc *fixedRateSenderControl) OnWrite(htype byte, x bool, seqno int64) (ccval byte, options []*Option) { return 0, nil }

func (scc *fixedRateSenderControl) OnRead(htype byte, x bool, seqno int64, options []Option) os.Error { return nil }
func (scc *fixedRateSenderControl) OnRead(htype byte, x bool, seqno int64, options []*Option) os.Error { return nil }

func (scc *fixedRateSenderControl) Strobe() os.Error {
_, ok := <-scc.strobeRead
Expand Down Expand Up @@ -98,9 +98,9 @@ func (rcc *fixedRateReceiverControl) Start() {

func (rcc *fixedRateReceiverControl) GetID() byte { return CCID_FIXED }

func (rcc *fixedRateReceiverControl) OnWrite(htype byte, x bool, seqno int64) (options []Option) { return nil }
func (rcc *fixedRateReceiverControl) OnWrite(htype byte, x bool, seqno int64) (options []*Option) { return nil }

func (rcc *fixedRateReceiverControl) OnRead(htype byte, x bool, seqno int64, ccval byte, options []Option) os.Error {
func (rcc *fixedRateReceiverControl) OnRead(htype byte, x bool, seqno int64, ccval byte, options []*Option) os.Error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion dccp/header.go
Expand Up @@ -29,7 +29,7 @@ type Header struct {
ServiceCode uint32 // ServiceCode: Applicaton level service (in Req,Resp pkts)
ResetCode byte // ResetCode: Reason for reset (in Reset pkts)
ResetData []byte // ResetData: Additional reset info (in Reset pkts)
Options []Option // Used for feature negotiation, padding, mandatory flags
Options []*Option // Used for feature negotiation, padding, mandatory flags
Data []byte // Application data (in Req, Resp, Data, DataAck pkts)
// Ignored (in Ack, Close, CloseReq, Sync, SyncAck pkts)
// Error text (in Reset pkts)
Expand Down
12 changes: 6 additions & 6 deletions dccp/options.go
Expand Up @@ -44,7 +44,7 @@ func isOptionCCIDSenderToReceiver(optionType byte) bool {
return (optionType >= 38 && optionType <= 43) || (optionType >= 128 && optionType <= 191)
}

func validateCCIDSenderToReceiver(opts []Option) bool {
func validateCCIDSenderToReceiver(opts []*Option) bool {
for _, o := range opts {
if !isOptionCCIDSenderToReceiver(o.Type) {
return false
Expand All @@ -53,8 +53,8 @@ func validateCCIDSenderToReceiver(opts []Option) bool {
return true
}

func filterCCIDSenderToReceiverOptions(opts []Option) []Option {
r := make([]Option, len(opts))
func filterCCIDSenderToReceiverOptions(opts []*Option) []*Option {
r := make([]*Option, len(opts))
k := 0
for _, o := range opts {
if isOptionCCIDSenderToReceiver(o.Type) {
Expand All @@ -69,7 +69,7 @@ func isOptionCCIDReceiverToSender(optionType byte) bool {
return (optionType >= 38 && optionType <= 43) || (optionType >= 192 && optionType <= 255)
}

func validateCCIDReceiverToSender(opts []Option) bool {
func validateCCIDReceiverToSender(opts []*Option) bool {
for _, o := range opts {
if !isOptionCCIDReceiverToSender(o.Type) {
return false
Expand All @@ -78,8 +78,8 @@ func validateCCIDReceiverToSender(opts []Option) bool {
return true
}

func filterCCIDReceiverToSenderOptions(opts []Option) []Option {
r := make([]Option, len(opts))
func filterCCIDReceiverToSenderOptions(opts []*Option) []*Option {
r := make([]*Option, len(opts))
k := 0
for _, o := range opts {
if isOptionCCIDReceiverToSender(o.Type) {
Expand Down
22 changes: 14 additions & 8 deletions dccp/read.go
Expand Up @@ -160,21 +160,25 @@ func ReadHeader(buf []byte,
return gh, nil
}

func readOptions(buf []byte) ([]Option, os.Error) {
func readOptions(buf []byte) ([]*Option, os.Error) {
if len(buf)&0x3 != 0 {
return nil, ErrAlign
}

opts := make([]Option, len(buf))
opts := make([]*Option, len(buf))
j, k := 0, 0
for k < len(buf) {
o := &Option{}

// Read option type
t := buf[k]
k += 1

if isOptionSingleByte(t) {
opts[j].Type = t
opts[j].Data = make([]byte, 0)
o.Type = t
o.Data = make([]byte, 0)

opts[j] = o
j += 1
continue
}
Expand All @@ -189,18 +193,20 @@ func readOptions(buf []byte) ([]Option, os.Error) {
break
}

opts[j].Type = t
opts[j].Data = buf[k : k+l-2]
o.Type = t
o.Data = buf[k : k+l-2]
k += l - 2

opts[j] = o
j += 1

}

return opts[0:j], nil
}

func sanitizeOptionsAfterReading(Type byte, opts []Option) ([]Option, os.Error) {
r := make([]Option, len(opts))
func sanitizeOptionsAfterReading(Type byte, opts []*Option) ([]*Option, os.Error) {
r := make([]*Option, len(opts))
j := 0

nextIsMandatory := false
Expand Down
4 changes: 2 additions & 2 deletions dccp/write.go
Expand Up @@ -213,8 +213,8 @@ func (gh *Header) Write(sourceIP, destIP []byte,
return buf, nil
}

func writeOptions(opts []Option, buf []byte, Type byte) {
if len(buf)&0x3 != 0 {
func writeOptions(opts []*Option, buf []byte, Type byte) {
if len(buf) & 0x3 != 0 {
panic("logic")
}
k := 0
Expand Down

0 comments on commit 81411c4

Please sign in to comment.