Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding bonding capabilities #89

Open
dakser opened this issue Mar 29, 2024 · 0 comments
Open

Adding bonding capabilities #89

dakser opened this issue Mar 29, 2024 · 0 comments

Comments

@dakser
Copy link

dakser commented Mar 29, 2024

Hi, do you think could be possible to add bonding capabilities to engarde? What do you think about this code?

Server:
// Import necessary packages

// Define a struct for storing bonded interfaces
type BondedInterfaces struct {
Interfaces []*net.UDPConn
}

// Initialize bonded interfaces
var bondedInterfaces BondedInterfaces

// Function to bond multiple network interfaces
func bondInterfaces() {
// Add code to initialize and bind multiple network interfaces
// For example, iterate through available interfaces and create UDP connections
// Store these connections in bondedInterfaces.Interfaces slice
}

// Function to distribute outgoing traffic across bonded interfaces
func distributeTraffic(data []byte) {
// Iterate through bonded interfaces and send data over each interface
for _, conn := range bondedInterfaces.Interfaces {
_, err := conn.Write(data)
if err != nil {
log.Warn("Error writing to bonded interface:", err)
}
}
}

// Modify main function to include bonding
func main() {
// Initialize bonded interfaces
bondInterfaces()

// Add other existing logic...

// Modify the existing send function to distribute traffic
go receiveFromClientBonded(ClientSocket, WireguardSocket, WireguardAddr)

}

// Modify existing send function to include bonding capabilities
func receiveFromClientBonded(socket, wgSocket *net.UDPConn, wgAddr *net.UDPAddr) {
buffer := make([]byte, 1500)
for {
n, srcAddr, err := socket.ReadFromUDP(buffer)
if err != nil {
log.Warn("Error reading from client")
continue
}

    // Distribute traffic across bonded interfaces
    go distributeTraffic(buffer[:n])
}

}

Client:
// Import necessary packages

// Modify main function to include bonding
func main() {
// Initialize bonded interfaces
bondInterfaces()

// Add other existing logic...

// Modify the existing receive function to handle bonded interfaces
go receiveFromWireguardBonded(WireguardSocket, &WireguardAddr)

}

// Modify existing receive function to handle bonded interfaces
func receiveFromWireguardBonded(wgsock *net.UDPConn, sourceAddr **net.UDPAddr) {
buffer := make([]byte, 1500)
for {
n, srcAddr, err := wgsock.ReadFromUDP(buffer)
if err != nil {
log.Warn("Error reading from Wireguard")
continue
}
*sourceAddr = srcAddr

    // Send received data to client application
    sendToClientBonded(buffer[:n])
}

}

// Function to send data to client application over bonded interfaces
func sendToClientBonded(data []byte) {
// Add code to send data to client application over bonded interfaces
// For example, distribute data across bonded connections
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant