conn

package
v2.2.0-alpha7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

README

Connection Package Documentation

This package contains the events that are triggered during the ingress call, capturing both the input and output of the user API call.

Documentation

Overview

Package conn provides functionality for handling connections.

Index

Constants

View Source
const (
	EventBodyMaxSize = 16384 // 16 KB
)

constant for the maximum size of the event body

Variables

View Source
var Emoji = "\U0001F430" + " Keploy:"

Functions

func ConvertUnixNanoToTime

func ConvertUnixNanoToTime(unixNano uint64) time.Time

ConvertUnixNanoToTime takes a Unix timestamp in nanoseconds as a uint64 and returns the corresponding time.Time

func ListenSocket

func ListenSocket(ctx context.Context, l *zap.Logger, openMap, dataMap, closeMap *ebpf.Map, opts models.IncomingOptions) (<-chan *models.TestCase, error)

ListenSocket starts the socket event listeners

Types

type Factory

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

Factory is a routine-safe container that holds a trackers with unique ID, and able to create new tracker.

func NewFactory

func NewFactory(inactivityThreshold time.Duration, logger *zap.Logger) *Factory

NewFactory creates a new instance of the factory.

func (*Factory) GetOrCreate

func (factory *Factory) GetOrCreate(connectionID ID) *Tracker

GetOrCreate returns a tracker that related to the given conn and transaction ids. If there is no such tracker we create a new one.

func (*Factory) ProcessActiveTrackers

func (factory *Factory) ProcessActiveTrackers(ctx context.Context, t chan *models.TestCase, opts models.IncomingOptions)

ProcessActiveTrackers iterates over all conn the trackers and checks if they are complete. If so, it captures the ingress call and deletes the tracker. If the tracker is inactive for a long time, it deletes it.

type ID

type ID struct {
	TGID uint32
	FD   int32
	TsID uint64
}

ID is a conversion of the following C-Struct into GO.

struct conn_id_t {
   uint32_t tgid;
   int32_t fd;
   uint64_t tsid;
};

type SockAddrIn

type SockAddrIn struct {
	SinFamily uint16
	SinPort   uint16
	SinAddr   uint32
	SinZero   [8]byte
}

SockAddrIn is a conversion of the following C-Struct into GO.

struct sockaddr_in {
   unsigned short int sin_family;
   uint16_t sin_port;
   struct in_addr sin_addr;

   /* _to size of `struct sockaddr'.  */
   unsigned char sin_zero[8];
};.

type SocketCloseEvent

type SocketCloseEvent struct {
	TimestampNano uint64
	ConnID        ID
	WrittenBytes  int64
	ReadBytes     int64
}

SocketCloseEvent is a conversion of the following C-Struct into GO.

struct socket_close_event_t {
   uint64_t timestamp_ns;
   struct conn_id_t conn_id;
   int64_t wr_bytes;
   int64_t rd_bytes;
};.

type SocketDataEvent

type SocketDataEvent struct {
	EntryTimestampNano   uint64
	TimestampNano        uint64
	ConnID               ID
	Direction            TrafficDirectionEnum
	MsgSize              uint32
	Pos                  uint64
	Msg                  [EventBodyMaxSize]byte
	ValidateReadBytes    int64
	ValidateWrittenBytes int64
}

SocketDataEvent is a conversion of the following C-Struct into GO. struct socket_data_event_t

{
    u64 entry_timestamp_ns;
    u64 timestamp_ns;
    struct conn_id_t conn_id;
    enum traffic_direction_t direction;
    u32 msg_size;
    u64 pos;
    char msg[MAX_MSG_SIZE];
    s64 validate_rd_bytes
    s64 validate_wr_bytes
};

type SocketOpenEvent

type SocketOpenEvent struct {
	TimestampNano uint64
	ConnID        ID
	Addr          SockAddrIn
}

SocketOpenEvent is a conversion of the following C-Struct into GO.

struct socket_open_event_t {
   uint64_t timestamp_ns;
   struct conn_id_t conn_id;
   struct sockaddr_in* addr;
};.

type Tracker

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

Tracker is a routine-safe container that holds a conn with unique ID, and able to create new conn.

func NewTracker

func NewTracker(connID ID, logger *zap.Logger) *Tracker

func (*Tracker) AddCloseEvent

func (conn *Tracker) AddCloseEvent(event SocketCloseEvent)

func (*Tracker) AddDataEvent

func (conn *Tracker) AddDataEvent(event SocketDataEvent)

func (*Tracker) AddOpenEvent

func (conn *Tracker) AddOpenEvent(event SocketOpenEvent)

func (*Tracker) IsComplete

func (conn *Tracker) IsComplete() (bool, []byte, []byte, time.Time, time.Time)

IsComplete checks if the current conn has valid request & response info to capture and also returns the request and response data buffer.

func (*Tracker) IsInactive

func (conn *Tracker) IsInactive(duration time.Duration) bool

func (*Tracker) ToBytes

func (conn *Tracker) ToBytes() ([]byte, []byte)

func (*Tracker) UpdateTimestamps

func (conn *Tracker) UpdateTimestamps()

type TrafficDirectionEnum

type TrafficDirectionEnum int32

TrafficDirectionEnum is a GO-equivalent for the following enum.

enum traffic_direction_t {
	kEgress,
	kIngress,
};.
const (
	EgressTraffic  TrafficDirectionEnum = 0
	IngressTraffic TrafficDirectionEnum = 1
)

constants for the TrafficDirectionEnum

func (TrafficDirectionEnum) String

func (t TrafficDirectionEnum) String() string

Jump to

Keyboard shortcuts

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