libp2pvpn

package module
v0.0.0-...-f180c14 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 12 Imported by: 0

README

go-libp2p-vpn

go-libp2p's VPN

Package go-libp2p-vpn is a VPN over libp2p.

Install

go get github.com/balena/go-libp2p-vpn

How to use

package main

import (
  "github.com/libp2p/go-libp2p"
  "github.com/balena/go-libp2p-vpn"
)

func main() {
  // Create the libp2p host
  host, err := libp2p.New()

  // Then create the VPN interface
  vpn, _ := libp2pvpn.New(peer)
 
  // Now set the stream handler (p2p->if)
  host.SetStreamHandler(vpn.Protocol(), vpn.Handler())

  // And serve packets (if->p2p)
  vpn.Serve(ctx, host)
}

Above example is overly simplified, double check the options passed to libp2p.New() and to libp2pvpn.New().

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the libp2p Code of Conduct.

Want to hack on libp2p?

License

MIT © 2023 Guilherme Versiani

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	water.Config
	LinkOptions
}

Config defines parameters required to create a TUN/TAP interface. It's only used when the device is initialized. A zero-value Config is a valid configuration.

type Interface

type Interface struct {
	*water.Interface
}

Defines a VPN interface.

func NewDevice

func NewDevice(opts ...Option) (*Interface, error)

Creates a new VPN device.

type LinkOptions

type LinkOptions struct {
	LocalAddress  string
	RemoteAddress string
	MTU           int
}

LinkOptions defines parameters in Config that are specific to Linux. A zero-value of such type is valid, yielding an interface with default values.

type Option

type Option func(cfg *Config)

Defines a VPN device modifier option.

func DevicePermissions

func DevicePermissions(permissions *water.DevicePermissions) Option

Permissions, if non-nil, specifies the owner and group owner for the interface. A zero-value of this field, i.e. nil, indicates that no changes to owner or group will be made.

func DeviceType

func DeviceType(deviceType water.DeviceType) Option

func LocalAddress

func LocalAddress(address string) Option

Sets the interface's local address and subnet.

func MTU

func MTU(mtu int) Option

SetMTU sets the Maximum Tansmission Unit Size for a Packet on the interface.

func MultiQueue

func MultiQueue(multiQueue bool) Option

MultiQueue specifies whether the multiqueue flag should be set on the interface. From version 3.8, Linux supports multiqueue tuntap which can uses multiple file descriptors (queues) to parallelize packets sending or receiving.

func Name

func Name(name string) Option

Name is the name to be set for the interface to be created. This overrides the default name assigned by OS such as tap0 or tun0. A zero-value of this field, i.e. an empty string, indicates that the default name should be used.

func Persist

func Persist(persist bool) Option

Persist specifies whether persistence mode for the interface device should be enabled or disabled.

func TunnelIP

func TunnelIP(local, remote string) Option

type VPNService

type VPNService struct {
	*Interface
	// contains filtered or unexported fields
}

func New

func New(peer peer.ID, opts ...Option) (*VPNService, error)

func (*VPNService) Handler

func (vpn *VPNService) Handler() network.StreamHandler

func (*VPNService) Protocol

func (vpn *VPNService) Protocol() protocol.ID

func (*VPNService) Serve

func (vpn *VPNService) Serve(ctx context.Context, host host.Host)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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