# OpenFlux Transport Interface Definition: Location, Methods, and Implementation Guide

> Discover the OpenFlux transport interface definition in transporttransport.go. Learn about its six essential methods Start Stop Send Receive IsConnected and Stats for implementing custom transports.

- Repository: [p1neappleXpress/OpenFlux](https://github.com/p1neappleXpress/OpenFlux)
- Tags: api-reference
- Published: 2026-09-13

---

**The OpenFlux transport interface definition resides in [`transport/transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/transport.go) at lines 17-23, defining the `Transport` interface with six essential methods—Start, Stop, Send, Receive, IsConnected, and Stats—that all transport implementations must satisfy.**

The p1neappleXpress/OpenFlux project implements a modular networking layer where the OpenFlux transport interface definition serves as the foundational contract between the core application and various network backends. This interface abstracts raw sockets, encrypted channels, and protocol-specific transports behind a unified API. Understanding this contract is essential for developers extending OpenFlux with custom transport mechanisms or debugging existing implementations.

## Location and Structure of the Transport Interface

The primary definition lives in [`transport/transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/transport.go) within the repository root. At lines 17-23, the source code declares the `Transport` interface that governs every send and receive operation in the system.

```go
type Transport interface {
    Start() error                         // Initialize and open the transport
    Stop() error                          // Gracefully shut it down
    Send(data []byte) error               // Transmit a raw packet
    Receive(callback func([]byte))        // Register a callback for incoming packets
    IsConnected() bool                    // Query the current connection state
    Stats() TransportStats                // Retrieve runtime statistics
}

```

This contract ensures that the main application in [`main.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/main.go) can initialize any transport without knowing implementation details, enabling seamless swapping between raw sockets, Windivert drivers, or encrypted tunnels.

## Core Methods and Lifecycle Contract

Each method in the OpenFlux transport interface definition serves a specific purpose in the packet flow lifecycle.

### Start and Stop Methods

The `Start() error` method initializes the transport and opens underlying network resources, while `Stop() error` handles graceful shutdown and resource cleanup. These methods manage the connection state that `IsConnected() bool` subsequently reports.

### Data Transfer Methods

`Send(data []byte) error` transmits raw packets through the transport layer, returning errors if the underlying socket fails. The `Receive(callback func([]byte))` method implements an asynchronous receive pattern, registering a callback function invoked for every incoming payload rather than returning data directly.

### Inspection and Statistics

`Stats() TransportStats` returns a snapshot of runtime metrics including uptime, bytes sent, and packet counts, enabling monitoring without interrupting active connections.

## Architectural Components

The interface supports a layered architecture where reusable components and concrete implementations coexist.

### BaseTransport Foundation

The same file ([`transport/transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/transport.go)) provides `BaseTransport`, a struct embedding common functionality for connection handling, statistics collection, and reconnection logic. Concrete transports embed `BaseTransport` to inherit standard behavior while overriding protocol-specific methods.

### Concrete Implementations

Several packages provide specialized implementations of the OpenFlux transport interface definition:

- [`transport/encrypted.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/encrypted.go) wraps any base transport with **AES-256-GCM encryption** while maintaining the same interface
- [`transport/oneme/max_transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/oneme/max_transport.go) implements protocol-specific behavior for the OneMe network
- [`transport/yandex/yandex.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/yandex/yandex.go) provides Yandex-based transport mechanisms

Each implementation satisfies the six-method contract while adding unique connection logic, proving the interface abstraction works across diverse networking approaches.

## Practical Implementation Examples

Working with the interface follows a consistent pattern regardless of underlying transport type.

### Creating a Transport Instance

```go
cfg := transport.DefaultConfig()
base := transport.NewBaseTransport(cfg)

// Wrap the base transport with encryption (optional)
enc, err := transport.NewEncryptedTransport(base, "sharedSecret", "sessionContext", false)
if err != nil {
    log.Fatalf("Failed to create encrypted transport: %v", err)
}

```

### Initializing and Registering Receivers

```go
if err := enc.Start(); err != nil {
    log.Fatalf("Transport start failed: %v", err)
}

// Register a callback that prints received payloads
enc.Receive(func(payload []byte) {
    fmt.Printf("Received %d bytes: %x\n", len(payload), payload)
})

```

### Sending Data and Monitoring

```go
packet := []byte{0x01, 0x02, 0x03, 0x04}
if err := enc.Send(packet); err != nil {
    log.Printf("Send error: %v", err)
}

// Inspect runtime statistics
stats := enc.Stats()
fmt.Printf("Uptime: %s, Bytes sent: %d, Packets sent: %d\n",
    stats.Uptime, stats.BytesSent, stats.PacketsSent)

```

## Key Source Files Reference

Understanding the OpenFlux transport interface definition requires navigating several related files:

- [`transport/transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/transport.go) – Declares the `Transport` interface, `BaseTransport` struct, and default configuration
- [`transport/encrypted.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/encrypted.go) – Implements encrypted wrapper fulfilling the interface
- [`transport/oneme/max_transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/oneme/max_transport.go) – Example concrete transport implementation
- [`transport/yandex/yandex.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/yandex/yandex.go) – Yandex-specific transport backend
- [`tunnel/packettunnel.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/tunnel/packettunnel.go) – Higher-level tunnel consuming the `Transport` interface

## Summary

- The **OpenFlux transport interface definition** is located in [`transport/transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/transport.go) at lines 17-23
- The interface specifies six methods: **Start**, **Stop**, **Send**, **Receive**, **IsConnected**, and **Stats**
- **BaseTransport** provides reusable foundation logic in the same file
- Concrete implementations in [`transport/encrypted.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/encrypted.go), `transport/oneme/`, and `transport/yandex/` prove the abstraction works across encrypted and protocol-specific channels
- The main application relies exclusively on this interface, enabling transport swapping without core code changes

## Frequently Asked Questions

### Where is the OpenFlux transport interface definition located?

The interface definition resides in [`transport/transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/transport.go) within the p1neappleXpress/OpenFlux repository, specifically at lines 17-23. This file also contains the `BaseTransport` implementation that concrete transports embed for shared functionality.

### What methods must a type implement to satisfy the Transport interface?

A valid implementation must provide six methods: `Start() error` and `Stop() error` for lifecycle management, `Send([]byte) error` and `Receive(func([]byte))` for data transfer, `IsConnected() bool` for state queries, and `Stats() TransportStats` for metrics retrieval.

### How does BaseTransport relate to the Transport interface?

`BaseTransport` is a struct defined in [`transport/transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/transport.go) that provides common connection handling, statistics tracking, and reconnection logic. While it does not fully implement the `Transport` interface alone, concrete transports embed it to inherit standard behavior while implementing protocol-specific details.

### Can I create custom transport implementations for OpenFlux?

Yes. By implementing the six-method `Transport` interface defined in [`transport/transport.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/transport/transport.go), you can create custom transports in new packages (e.g., `transport/custom/`) without modifying the core application. The main [`main.go`](https://github.com/p1neappleXpress/OpenFlux/blob/main/main.go) consumes any type satisfying this interface, allowing seamless integration of new networking backends.