Documentation ¶
Index ¶
- Constants
- Variables
- func CalculateChecksum(buffer []byte) uint16
- func ExtractIpPayload(ipFrame []byte) (int, error)
- func GenerateISN() (uint32, error)
- func NewPayload(params ...interface{}) rp.DataInterface
- func SeqIncrement(seq uint32) uint32
- func SeqIncrementBy(seq, inc uint32) uint32
- func SetEmptySlice(length int)
- func SleepForMs(n int)
- func VerifyChecksum(data []byte, srcAddr, dstAddr net.Addr, protocolId uint8) bool
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) CloseAsGoRoutine(wg *sync.WaitGroup)
- func (c *Connection) GetMSS() int
- func (c *Connection) LocalAddr() *net.IPAddr
- func (c *Connection) LocalPort() int
- func (c *Connection) Read(buffer []byte) (int, error)
- func (c *Connection) RemoteAddr() *net.IPAddr
- func (c *Connection) RemotePort() int
- func (c *Connection) SetReadDeadline(t time.Time) error
- func (c *Connection) StartStatsPrinter()
- func (c *Connection) Write(buffer []byte) (int, error)
- type PacketGapMap
- type PacketInfo
- type Payload
- type PcpCore
- type PcpCoreConfig
- type PcpPacket
- func (p *PcpPacket) AddChannel(chanStr string)
- func (p *PcpPacket) AddFootPrint(fpStr string) int
- func (p *PcpPacket) CopyToPayload(src []byte) error
- func (p *PcpPacket) Duplicate() (*PcpPacket, error)
- func (p *PcpPacket) GetChunk()
- func (p *PcpPacket) GetChunkReference() *rp.Element
- func (p *PcpPacket) GetPayloadLength() int
- func (p *PcpPacket) Marshal(protocolId uint8, buffer []byte) (int, error)
- func (p *PcpPacket) ReturnChunk()
- func (p *PcpPacket) TickChannel() error
- func (p *PcpPacket) TickFootPrint(fp int)
- func (p *PcpPacket) Unmarshal(data []byte, srcAddr, destAddr net.Addr) error
- type PcpProtocolConnection
- type PortPool
- type ReceivedPacket
- type ResendPackets
- func (r *ResendPackets) AddSentPacket(packet *PcpPacket)
- func (r *ResendPackets) GetPacketKeys() []uint32
- func (r *ResendPackets) GetSentPacket(seqNum uint32) (*PacketInfo, bool)
- func (r *ResendPackets) RemovalLock()
- func (r *ResendPackets) RemovalUnlock()
- func (r *ResendPackets) RemoveSentPacket(seqNum uint32)
- func (r *ResendPackets) UpdateSentPacket(seqNum uint32) error
- type Service
- type TimeoutError
Constants ¶
const ( SynReceived = 1 // 3-way handshake server state SynAckSent = 2 // 3-way handshake server state AckReceived = 3 // 3-way handshake server state SynSent = 1 // 3-way handshake client state SynAckReceived = 2 // 3-way handshake client state AckSent = 3 // 3-way handshake client state CallerFinSent = 1 // 4-way termination caller state CallerFinAckReceived = 2 // 4-way termination caller state CallerAckSent = 3 // 4-way termination caller state RespFinReceived = 1 // 4-way termination responder state RespFinAckSent = 2 // 4-way termination responder state RespAckReceived = 3 // 4-way termination responder state )
const ( // PCP flag constants URGFlag uint8 = 1 << 5 ACKFlag uint8 = 1 << 4 PSHFlag uint8 = 1 << 3 RSTFlag uint8 = 1 << 2 SYNFlag uint8 = 1 << 1 FINFlag uint8 = 1 << 0 )
Flag constants
const ( Red = "\033[31m" Reset = "\033[0m" ColorRed = "\033[31m" ColorGreen = "\033[32m" ColorYellow = "\033[33m" ColorBlue = "\033[34m" ColorMagenta = "\033[35m" ColorCyan = "\033[36m" ColorReset = "\033[0m" )
const ( TcpOptionsMaxLength = 40 TcpHeaderLength = 20 //options not included TcpPseudoHeaderLength = 12 IpHeaderMaxLength = 60 )
Variables ¶
var (
Pool *rp.RingPool
)
Functions ¶
func CalculateChecksum ¶
func ExtractIpPayload ¶
Function to extract payload from an IP packet
func GenerateISN ¶
func NewPayload ¶
func NewPayload(params ...interface{}) rp.DataInterface
Define a function that creates a new instance of ConcreteData
func SeqIncrement ¶
func SeqIncrementBy ¶
func SetEmptySlice ¶
func SetEmptySlice(length int)
Types ¶
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
func (*Connection) CloseAsGoRoutine ¶
func (c *Connection) CloseAsGoRoutine(wg *sync.WaitGroup)
c.close function wrapped up as go routine
func (*Connection) GetMSS ¶
func (c *Connection) GetMSS() int
func (*Connection) LocalAddr ¶
func (c *Connection) LocalAddr() *net.IPAddr
func (*Connection) LocalPort ¶
func (c *Connection) LocalPort() int
func (*Connection) RemoteAddr ¶
func (c *Connection) RemoteAddr() *net.IPAddr
func (*Connection) RemotePort ¶
func (c *Connection) RemotePort() int
func (*Connection) SetReadDeadline ¶
func (c *Connection) SetReadDeadline(t time.Time) error
func (*Connection) StartStatsPrinter ¶
func (c *Connection) StartStatsPrinter()
type PacketGapMap ¶
type PacketGapMap struct {
// contains filtered or unexported fields
}
func NewPacketGapMap ¶
func NewPacketGapMap() *PacketGapMap
func (*PacketGapMap) AddPacket ¶
func (pgm *PacketGapMap) AddPacket(packet *PcpPacket)
func (*PacketGapMap) GetPacket ¶
func (pgm *PacketGapMap) GetPacket(seqNum uint32) (*ReceivedPacket, bool)
func (*PacketGapMap) RemovePacket ¶
func (pgm *PacketGapMap) RemovePacket(seqNum uint32)
type PacketInfo ¶
type PacketInfo struct { LastSentTime time.Time // Time the packet was last sent ResendCount int // Number of times the packet has been resent Data *PcpPacket }
PacketInfo represents information about a sent packet
type Payload ¶
type Payload struct {
// contains filtered or unexported fields
}
PayloadBytes represents packet payload byte slice
func (*Payload) PrintContent ¶
func (p *Payload) PrintContent()
PrintContent prints the content of the payload
type PcpCore ¶
type PcpCore struct {
// contains filtered or unexported fields
}
func NewPcpCore ¶
func NewPcpCore(pcpcoreConfig *PcpCoreConfig) (*PcpCore, error)
type PcpCoreConfig ¶
type PcpCoreConfig struct { ProtocolID uint8 // protocol id which should be 6 PayloadPoolSize int // how many number of packet payload chunks in the pool PreferredMSS int // preferred MSS Debug bool // global debug setting PoolDebug bool // Ring Pool debug setting ProcessTimeThreshold int // packet processing time threshold }
type PcpPacket ¶
type PcpPacket struct {
SrcAddr, DestAddr net.Addr
SourcePort uint16 // SourcePort represents the source port
DestinationPort uint16 // DestinationPort represents the destination port
SequenceNumber uint32 // SequenceNumber represents the sequence number
AcknowledgmentNum uint32 // AcknowledgmentNum represents the acknowledgment number
WindowSize uint16 // WindowSize specifies the number of bytes the receiver is willing to receive
Flags uint8 // Flags represent various control flags
UrgentPointer uint16 // UrgentPointer indicates the end of the urgent data (empty for now)
Checksum uint16 // Checksum is the checksum of the packet
Payload []byte // Payload represents the payload data
TcpOptions *options
IsOpenConnection bool // only used in outgoing packet to denote if the connection is open or in 3-way handshake stage
Conn *Connection // used for outgoing packets only to denote which connection it belongs to
IsKeepAliveMassege bool // denote if this is a keepalive massage. If yes, don't put it into Connection's ResendPackets
// contains filtered or unexported fields
}
PcpPacket represents a packet in your custom protocol
func NewPcpPacket ¶
func NewPcpPacket(seqNum, ackNum uint32, flags uint8, data []byte, conn *Connection) *PcpPacket
func (*PcpPacket) AddChannel ¶
func (*PcpPacket) AddFootPrint ¶
func (*PcpPacket) CopyToPayload ¶
func (*PcpPacket) GetChunkReference ¶
func (*PcpPacket) GetPayloadLength ¶
func (*PcpPacket) ReturnChunk ¶
func (p *PcpPacket) ReturnChunk()
func (*PcpPacket) TickChannel ¶
func (*PcpPacket) TickFootPrint ¶
type PcpProtocolConnection ¶
type PcpProtocolConnection struct {
// contains filtered or unexported fields
}
pcp protocol connection struct
func (*PcpProtocolConnection) Close ¶
func (p *PcpProtocolConnection) Close()
Function to close the connection gracefully
type PortPool ¶
type PortPool struct {
// contains filtered or unexported fields
}
PortPool manages a pool of port numbers for TCP local port number allocation it makes use of ring pool implemetation
type ReceivedPacket ¶
type ReceivedPacket struct { ReceivedTime time.Time // Time the packet was last sent Packet *PcpPacket }
func NewReceivedPacket ¶
func NewReceivedPacket(packet *PcpPacket) *ReceivedPacket
type ResendPackets ¶
type ResendPackets struct {
// contains filtered or unexported fields
}
func NewResendPackets ¶
func NewResendPackets() *ResendPackets
func (*ResendPackets) AddSentPacket ¶
func (r *ResendPackets) AddSentPacket(packet *PcpPacket)
Function to add a sent packet to the map
func (*ResendPackets) GetPacketKeys ¶
func (r *ResendPackets) GetPacketKeys() []uint32
func (*ResendPackets) GetSentPacket ¶
func (r *ResendPackets) GetSentPacket(seqNum uint32) (*PacketInfo, bool)
Function to update information about a sent packet
func (*ResendPackets) RemovalLock ¶
func (r *ResendPackets) RemovalLock()
func (*ResendPackets) RemovalUnlock ¶
func (r *ResendPackets) RemovalUnlock()
func (*ResendPackets) RemoveSentPacket ¶
func (r *ResendPackets) RemoveSentPacket(seqNum uint32)
Function to remove a sent packet from the map
func (*ResendPackets) UpdateSentPacket ¶
func (r *ResendPackets) UpdateSentPacket(seqNum uint32) error
Function to update information about a sent packet
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a service listening on a specific port.
func (*Service) Accept ¶
func (s *Service) Accept() (*Connection, error)
Accept accepts incoming connection requests.
type TimeoutError ¶
type TimeoutError struct {
// contains filtered or unexported fields
}
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
func (*TimeoutError) Temporary ¶
func (e *TimeoutError) Temporary() bool
func (*TimeoutError) Timeout ¶
func (e *TimeoutError) Timeout() bool