lib

package
v0.0.0-...-7595b59 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
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

View Source
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"
)
View Source
const (
	TcpOptionsMaxLength   = 40
	TcpHeaderLength       = 20 //options not included
	TcpPseudoHeaderLength = 12
	IpHeaderMaxLength     = 60
)

Variables

View Source
var (
	Pool *rp.RingPool
)

Functions

func CalculateChecksum

func CalculateChecksum(buffer []byte) uint16

func ExtractIpPayload

func ExtractIpPayload(ipFrame []byte) (int, error)

Function to extract payload from an IP packet

func GenerateISN

func GenerateISN() (uint32, error)

func NewPayload

func NewPayload(params ...interface{}) rp.DataInterface

Define a function that creates a new instance of ConcreteData

func SeqIncrement

func SeqIncrement(seq uint32) uint32

func SeqIncrementBy

func SeqIncrementBy(seq, inc uint32) uint32

func SetEmptySlice

func SetEmptySlice(length int)

func SleepForMs

func SleepForMs(n int)

sleep for n milliseconds

func VerifyChecksum

func VerifyChecksum(data []byte, srcAddr, dstAddr net.Addr, protocolId uint8) bool

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func (*Connection) Close

func (c *Connection) Close() error

PCP connection close

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) Read

func (c *Connection) Read(buffer []byte) (int, error)

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()

func (*Connection) Write

func (c *Connection) Write(buffer []byte) (int, error)

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) Copy

func (p *Payload) Copy(src []byte) error

func (*Payload) GetSlice

func (p *Payload) GetSlice() []byte

func (*Payload) PrintContent

func (p *Payload) PrintContent()

PrintContent prints the content of the payload

func (*Payload) Reset

func (p *Payload) Reset()

Reset resets the content of the payload

func (*Payload) SetContent

func (p *Payload) SetContent(s string)

set the content of the payload

type PcpCore

type PcpCore struct {
	// contains filtered or unexported fields
}

func NewPcpCore

func NewPcpCore(pcpcoreConfig *PcpCoreConfig) (*PcpCore, error)

func (*PcpCore) Close

func (p *PcpCore) Close() error

func (*PcpCore) DialPcp

func (p *PcpCore) DialPcp(localIP string, serverIP string, serverPort uint16, pcpConfig *config.Config) (*Connection, error)

dialPcp simulates the TCP dial function interface for PCP.

func (*PcpCore) ListenPcp

func (p *PcpCore) ListenPcp(serviceIP string, port int, pcpConfig *config.Config) (*Service, error)

ListenPcp starts listening for incoming packets on the service's port.

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 (p *PcpPacket) AddChannel(chanStr string)

func (*PcpPacket) AddFootPrint

func (p *PcpPacket) AddFootPrint(fpStr string) int

func (*PcpPacket) CopyToPayload

func (p *PcpPacket) CopyToPayload(src []byte) error

func (*PcpPacket) Duplicate

func (p *PcpPacket) Duplicate() (*PcpPacket, error)

func (*PcpPacket) GetChunk

func (p *PcpPacket) GetChunk()

func (*PcpPacket) GetChunkReference

func (p *PcpPacket) GetChunkReference() *rp.Element

func (*PcpPacket) GetPayloadLength

func (p *PcpPacket) GetPayloadLength() int

func (*PcpPacket) Marshal

func (p *PcpPacket) Marshal(protocolId uint8, buffer []byte) (int, error)

Marshal converts a PcpPacket to a byte slice

func (*PcpPacket) ReturnChunk

func (p *PcpPacket) ReturnChunk()

func (*PcpPacket) TickChannel

func (p *PcpPacket) TickChannel() error

func (*PcpPacket) TickFootPrint

func (p *PcpPacket) TickFootPrint(fp int)

func (*PcpPacket) Unmarshal

func (p *PcpPacket) Unmarshal(data []byte, srcAddr, destAddr net.Addr) error

Unmarshal converts a byte slice to a PcpPacket

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.

func (*Service) Close

func (s *Service) Close() error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL