Skip to content

Commit

Permalink
[net/tcp] Fixed due to others changes
Browse files Browse the repository at this point in the history
  • Loading branch information
OmidHekayati committed Sep 20, 2024
1 parent 4288fd3 commit f94f570
Show file tree
Hide file tree
Showing 31 changed files with 192 additions and 171 deletions.
14 changes: 7 additions & 7 deletions net/tcp/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package tcp

import (
"memar/timer"
"memar/time/duration"
)

// ATTENTION:::: Don't changed below settings without any good reason
Expand Down Expand Up @@ -98,7 +98,7 @@ const (
CNF_DelayedAcknowledgment = true
// CNF_DelayedAcknowledgment_PerStream indicate that in init phase of each stream package must enable DelayedAcknowledgment.
CNF_DelayedAcknowledgment_PerStream = true
CNF_DelayedAcknowledgment_Timeout = 500 * timer.Millisecond
CNF_DelayedAcknowledgment_Timeout = 500 * duration.OneMillisecond
)

// Keep alive config values
Expand All @@ -113,9 +113,9 @@ const (
// The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes.
// terminated after approximately an additional CNF_KeepAlive_Probes*CNF_KeepAlive_Interval e.g.
// 9 probes an interval of 75 seconds apart be 11 minutes.
CNF_KeepAlive_Idle = 7200 * timer.Second // (2 hours)
CNF_KeepAlive_Idle = 7200 * duration.OneSecond // (2 hours)
// The number of seconds between TCP keep-alive probes.
CNF_KeepAlive_Interval = 75 * timer.Second
CNF_KeepAlive_Interval = 75 * duration.OneSecond
// The maximum number of TCP keep-alive probes to send before giving up and
// killing the socket connection if no response is obtained from the other end.
CNF_KeepAlive_Probes = 9
Expand All @@ -132,8 +132,8 @@ const (
// CNF_UserTimeout_PerStream indicate that in init phase of each stream package must enable UserTimeout.
CNF_UserTimeout_PerStream = true
CNF_UserTimeout_Retransmission = 3
CNF_UserTimeout_Idle = 100 * timer.Second
CNF_UserTimeout_SynIdle = 180 * timer.Second // (3 minutes)
CNF_UserTimeout_Idle = 100 * duration.OneSecond
CNF_UserTimeout_SynIdle = 180 * duration.OneSecond // (3 minutes)
)

// timeout config values
Expand Down Expand Up @@ -190,7 +190,7 @@ const (
// required to prevent denial-of-service attacks. In Linux
// 2.2, the default value was 180.
// This option should not be used in code intended to be portable.
CNF_FinTimeout = 60 * timer.Second
CNF_FinTimeout = 60 * duration.OneSecond
)

// segment config values
Expand Down
18 changes: 0 additions & 18 deletions net/tcp/errors.go

This file was deleted.

18 changes: 18 additions & 0 deletions net/tcp/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* For license and copyright information please see the LEGAL file in the code repository */

package errs

import (
er "memar/error"
)

// Errors
var (
SegmentTooShort er.Error
SegmentWrongLength er.Error
)

func init() {
SegmentTooShort.Init("domain/tcp.wg.ietf.org; type=error; name=packet-too-short")
SegmentWrongLength.Init("domain/tcp.wg.ietf.org; type=error; name=packet-wrong-length")
}
4 changes: 2 additions & 2 deletions net/tcp/option-alt-checksum-data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionAltChecksumData []byte
Expand All @@ -13,6 +13,6 @@ func (o optionAltChecksumData) Length() byte { return o[0] }
func (o optionAltChecksumData) AltChecksumData() uint16 { return binary.BigEndian(o[1:]).Uint16() } // unrecognised
func (o optionAltChecksumData) NextOption() []byte { return o[3:] }

func (o optionAltChecksumData) Process(s *Stream) (err protocol.Error) {
func (o optionAltChecksumData) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-alt-checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionAltChecksum []byte
Expand All @@ -13,6 +13,6 @@ func (o optionAltChecksum) Length() byte { return o[0] }
func (o optionAltChecksum) AltChecksum() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionAltChecksum) NextOption() []byte { return o[3:] }

func (o optionAltChecksum) Process(s *Stream) (err protocol.Error) {
func (o optionAltChecksum) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionCC []byte
Expand All @@ -13,6 +13,6 @@ func (o optionCC) Length() byte { return o[0] }
func (o optionCC) CC() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionCC) NextOption() []byte { return o[5:] }

func (o optionCC) Process(s *Stream) (err protocol.Error) {
func (o optionCC) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-ccecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionCCEcho []byte
Expand All @@ -13,6 +13,6 @@ func (o optionCCEcho) Length() byte { return o[0] }
func (o optionCCEcho) CCEcho() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionCCEcho) NextOption() []byte { return o[5:] }

func (o optionCCEcho) Process(s *Stream) (err protocol.Error) {
func (o optionCCEcho) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-ccnew.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionCCNew []byte
Expand All @@ -13,6 +13,6 @@ func (o optionCCNew) Length() byte { return o[0] }
func (o optionCCNew) CCNew() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionCCNew) NextOption() []byte { return o[5:] }

func (o optionCCNew) Process(s *Stream) (err protocol.Error) {
func (o optionCCNew) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-echo-reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionEchoReply []byte
Expand All @@ -13,6 +13,6 @@ func (o optionEchoReply) Length() byte { return o[0] }
func (o optionEchoReply) EchoReply() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionEchoReply) NextOption() []byte { return o[5:] }

func (o optionEchoReply) Process(s *Stream) (err protocol.Error) {
func (o optionEchoReply) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionEcho []byte
Expand All @@ -13,6 +13,6 @@ func (o optionEcho) Length() byte { return o[0] }
func (o optionEcho) Echo() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionEcho) NextOption() []byte { return o[5:] }

func (o optionEcho) Process(s *Stream) (err protocol.Error) {
func (o optionEcho) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-mss.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

/*
Expand All @@ -19,6 +19,6 @@ func (o optionMSS) Length() byte { return o[0] }
func (o optionMSS) MSS() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionMSS) NextOption() []byte { return o[3:] }

func (o optionMSS) Process(s *Stream) (err protocol.Error) {
func (o optionMSS) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-partial-order-connection-permitted.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package tcp

import (
"memar/protocol"
error_p "memar/error/protocol"
)

type optionPartialOrderConnectionPermitted []byte
Expand All @@ -15,6 +15,6 @@ func (o optionPartialOrderConnectionPermitted) Length() byte { return o[0] }
// }
func (o optionPartialOrderConnectionPermitted) NextOption() []byte { return o[3:] }

func (o optionPartialOrderConnectionPermitted) Process(s *Stream) (err protocol.Error) {
func (o optionPartialOrderConnectionPermitted) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-partial-order-service-profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

/*
Expand All @@ -26,6 +26,6 @@ func (o optionPartialOrderServiceProfile) PartialOrderServiceProfile() uint16 {
}
func (o optionPartialOrderServiceProfile) NextOption() []byte { return o[3:] }

func (o optionPartialOrderServiceProfile) Process(s *Stream) (err protocol.Error) {
func (o optionPartialOrderServiceProfile) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-stack-permited.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package tcp

import (
"memar/protocol"
error_p "memar/error/protocol"
)

type optionSACKPermitted []byte
Expand All @@ -13,6 +13,6 @@ func (o optionSACKPermitted) Length() byte { return o[0] }
// func (o optionSACKPermitted) SACKPermitted() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionSACKPermitted) NextOption() []byte { return o[1:] }

func (o optionSACKPermitted) Process(s *Stream) (err protocol.Error) {
func (o optionSACKPermitted) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-timestamps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionTimestamps []byte
Expand All @@ -13,6 +13,6 @@ func (o optionTimestamps) Length() byte { return o[0] }
func (o optionTimestamps) Timestamps() uint16 { return binary.BigEndian(o[1:]).Uint16() }
func (o optionTimestamps) NextOption() []byte { return o[8:] }

func (o optionTimestamps) Process(s *Stream) (err protocol.Error) {
func (o optionTimestamps) Process(s *Stream) (err error_p.Error) {
return
}
4 changes: 2 additions & 2 deletions net/tcp/option-window-scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
)

type optionWindowScale []byte
Expand All @@ -14,6 +14,6 @@ func (o optionWindowScale) WindowScale() uint16 { return binary.BigEndian(o[1:])
func (o optionWindowScale) NextOption() []byte { return o[2:] }

// handler options -> stream
func (o optionWindowScale) Process(s *Stream) (err protocol.Error) {
func (o optionWindowScale) Process(s *Stream) (err error_p.Error) {
return
}
10 changes: 5 additions & 5 deletions net/tcp/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package tcp

import (
"memar/protocol"
error_p "memar/error/protocol"
)

type port struct {
Expand All @@ -13,18 +13,18 @@ type port struct {

// Init use to initialize the stream after allocation in both server or client
//
//memar:impl memar/protocol.ObjectLifeCycle
func (p *port) Init(sourcePort, destinationPort PortNumber) (err protocol.Error) {
//memar:impl memar/computer/language/object/protocol.LifeCycle
func (p *port) Init(sourcePort, destinationPort PortNumber) (err error_p.Error) {
p.sourcePort = sourcePort
p.destinationPort = destinationPort
return
}
func (p *port) Reinit(sourcePort, destinationPort PortNumber) (err protocol.Error) {
func (p *port) Reinit(sourcePort, destinationPort PortNumber) (err error_p.Error) {
p.sourcePort = sourcePort
p.destinationPort = destinationPort
return
}
func (p *port) Deinit() (err protocol.Error) { return }
func (p *port) Deinit() (err error_p.Error) { return }

func (p *port) SourcePort() PortNumber { return p.sourcePort }
func (p *port) DestinationPort() PortNumber { return p.destinationPort }
9 changes: 5 additions & 4 deletions net/tcp/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ package tcp

import (
"memar/binary"
"memar/protocol"
error_p "memar/error/protocol"
errs "memar/net/tcp/errors"
)

// Segment implement all methods to Get||Set data to a segment as a byte slice with 0-alloc
Expand All @@ -13,13 +14,13 @@ type Segment []byte

// CheckSegment will check segment for any bad situation.
// Always check segment before use any other segment methods otherwise panic occur.
func (s Segment) CheckSegment() protocol.Error {
func (s Segment) CheckSegment() error_p.Error {
var segmentLen = len(s)
if segmentLen < CNF_Segment_MinSize {
return &ErrSegmentTooShort
return &errs.SegmentTooShort
}
if segmentLen < int(s.DataOffset()) {
return &ErrSegmentWrongLength
return &errs.SegmentWrongLength
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions net/tcp/stream-firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
package tcp

import (
"memar/protocol"
error_p "memar/error/protocol"
)

func (s *Stream) checkPushFlag() (err protocol.Error) {
func (s *Stream) checkPushFlag() (err error_p.Error) {
// TODO:::
return
}
Loading

0 comments on commit f94f570

Please sign in to comment.