meshboi

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 17 Imported by: 0

README

logo meshboi

meshboi is a toy mesh VPN implementation, created for fun and learning purposes. It allows the creation of peer to peer networks over the internet in a similar fashion to tools such as Nebula and Tailscale.

More information about how meshboi works is available on my blog post Creating a mesh VPN for fun and learning.

Quick Start

  1. Download the most recent release.
  2. Start meshboi on one host:
./meshboi client -rolodex-address rolodex.samlewis.me -vpn-ip 192.168.50.1/24 -psk <a secure password> -network <a unique network name>
  1. Start meshboi on another host:
./meshboi client -rolodex-address rolodex.samlewis.me -vpn-ip 192.168.50.2/24 -psk <same password as step 2> -network <same network name as part 2>
  1. The hosts should now be able to communicate as though they were on the same LAN!

Note that this will use the publicly accessible rolodex server that I host. No user data flows through this server other than metadata that contains the internet IP and ports of your instances (though this has not been properly audited, so please use at your own risk!). You are also free to host your own Rolodex server on an an internet accessible server (a cheap EC2 instance or equivalent will work fine). You can do so with:

./meshboi rolodex

And then use the IP address or hostname of this server when starting meshboi in client mode (with the -rolodex-address option).

Demo

An asciinema recording of meshboi in action:

asciinema

Documentation

Index

Constants

View Source
const (
	IFF_TUN   = 0x1    /* Flag to open a TUN device (rather than TAP) */
	IFF_NO_PI = 0x1000 /* Do not provide packet information */
)
View Source
const TimeOutSecs = 30

Variables

This section is empty.

Functions

func NewRolodex

func NewRolodex(conn *net.UDPConn, sendInterval time.Duration, timeOutDuration time.Duration) (*rolodex, error)

Types

type HeartbeatMessage

type HeartbeatMessage struct {
	NetworkName string
}

type MeshConn

type MeshConn interface {
	net.Conn
	RemoteMeshAddr() netaddr.IP
}

type MeshboiClient

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

func NewMeshBoiClient

func NewMeshBoiClient(tun TunConn, vpnIpPrefix netaddr.IPPrefix, rolodexIP netaddr.IP, rolodexPort int, networkName string, meshPSK []byte) (*MeshboiClient, error)

func (*MeshboiClient) Run

func (mc *MeshboiClient) Run()

func (*MeshboiClient) Stop

func (mc *MeshboiClient) Stop()

type MultiplexedDTLSConn

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

MultiplexedDTLSConn represents a conn that can be used to listen for new incoming DTLS connections and also dial new UDP connections (both DTLS and non-DTLS) from the same udp address

func NewMultiplexedDTLSConn

func NewMultiplexedDTLSConn(laddr *net.UDPAddr, config *dtls.Config) (*MultiplexedDTLSConn, error)

func (*MultiplexedDTLSConn) AcceptMesh

func (mc *MultiplexedDTLSConn) AcceptMesh() (MeshConn, error)

func (*MultiplexedDTLSConn) Dial

func (mc *MultiplexedDTLSConn) Dial(raddr net.Addr) (net.Conn, error)

func (*MultiplexedDTLSConn) DialMesh

func (mc *MultiplexedDTLSConn) DialMesh(raddr net.Addr) (MeshConn, error)

type NetworkMap

type NetworkMap struct {
	Addresses []netaddr.IPPort
	YourIndex int
}

type PeerConn

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

Represents a connection to a peer

func NewPeerConn

func NewPeerConn(insideIP netaddr.IP, outsideAddr netaddr.IPPort, conn net.Conn, tun TunConn) PeerConn

func (*PeerConn) QueueData

func (p *PeerConn) QueueData(data []byte)

type PeerConnStore

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

func NewPeerConnStore

func NewPeerConnStore() *PeerConnStore

func (*PeerConnStore) Add

func (p *PeerConnStore) Add(peer *PeerConn)

func (*PeerConnStore) GetByInsideIp

func (p *PeerConnStore) GetByInsideIp(insideIP netaddr.IP) (*PeerConn, bool)

func (*PeerConnStore) GetByOutsideIpPort

func (p *PeerConnStore) GetByOutsideIpPort(outsideIPPort netaddr.IPPort) (*PeerConn, bool)

func (*PeerConnStore) RemoveByOutsideIPPort

func (p *PeerConnStore) RemoveByOutsideIPPort(outsideIPPort netaddr.IPPort) bool

type PeerConnector

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

func NewPeerConnector

func NewPeerConnector(listenerDialer VpnMeshListenerDialer, store *PeerConnStore, tun TunConn) PeerConnector

func (*PeerConnector) AmServer

func (pc *PeerConnector) AmServer(other netaddr.IPPort) bool

Simple comparison to see if this member should be the server or if the remote member should be

func (*PeerConnector) ListenForPeers

func (pc *PeerConnector) ListenForPeers()

func (*PeerConnector) OnNetworkMapUpdate

func (pc *PeerConnector) OnNetworkMapUpdate(network NetworkMap)

func (*PeerConnector) OnNewPeerConnection

func (pc *PeerConnector) OnNewPeerConnection(conn MeshConn) error

func (*PeerConnector) Stop

func (pc *PeerConnector) Stop()

type RolodexCallback

type RolodexCallback func(member NetworkMap)

type RolodexClient

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

func NewRolodexClient

func NewRolodexClient(networkName string, conn net.Conn, sendRate time.Duration, callback RolodexCallback) RolodexClient

func (*RolodexClient) Run

func (c *RolodexClient) Run()

func (*RolodexClient) Stop

func (c *RolodexClient) Stop()

type Tun

type Tun struct {
	io.ReadWriteCloser
	Name string
}

func NewTunWithConfig

func NewTunWithConfig(name string, ip string, mtu int) (*Tun, error)

Makes a Tun with the desired config and immediately sets it up

func (Tun) SetLinkUp

func (t Tun) SetLinkUp() error

func (Tun) SetMtu

func (t Tun) SetMtu(mtu int) error

func (Tun) SetNetwork

func (t Tun) SetNetwork(ip string) error

type TunConn

type TunConn interface {
	io.ReadWriteCloser
}

type TunRouter

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

func NewTunRouter

func NewTunRouter(tun TunConn, store *PeerConnStore) TunRouter

func (*TunRouter) Run

func (tr *TunRouter) Run()

func (*TunRouter) Stop

func (tr *TunRouter) Stop() error

type VpnMeshListenerDialer

type VpnMeshListenerDialer interface {
	// Returns the connection and the VPN IP address on the other side
	AcceptMesh() (MeshConn, error)
	// Returns the connection and the VPN IP address on the other side
	DialMesh(raddr net.Addr) (MeshConn, error)
	Dial(raddr net.Addr) (net.Conn, error)
}

VpnListenerDialer allows for:

  • Dialing connections to other members in the VPN Mesh
  • Accepting connections to other members in the VPN Mesh
  • Dialing connections to non VPN Mesh members

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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