upnp

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MPL-2.0 Imports: 14 Imported by: 5

README

This is a fork of a syncthing/upnp module

Documentation

Overview

Package upnp implements UPnP InternetGatewayDevice discovery, querying, and port mapping.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Debug Set this to true to print debug information
	Debug = true
)

Functions

func Register

func Register(provider DiscoverFunc)

Types

type Address

type Address struct {
	IP   net.IP
	Port int
}

Address is essentially net.TCPAddr yet is more general, and has a few helper methods which reduce boilerplate code.

func (Address) Equal

func (a Address) Equal(b Address) bool

func (Address) GoString

func (a Address) GoString() string

func (Address) String

func (a Address) String() string

type Device

type Device interface {
	ID() string
	GetLocalIPAddress() net.IP
	AddPortMapping(protocol Protocol, internalPort, externalPort int, description string, duration time.Duration) (int, error)
	DeletePortMapping(protocol Protocol, externalPort int) error
	GetExternalIPAddress() (net.IP, error)
}

func Discover

func Discover(renewal, timeout time.Duration, logger log.Logger) []Device

Discover discovers UPnP InternetGatewayDevices. The order in which the devices appear in the results list is not deterministic.

type DiscoverFunc

type DiscoverFunc func(renewal, timeout time.Duration, _ log.Logger) []Device

type IGDService

type IGDService struct {
	UUID      string
	Device    upnpDevice
	ServiceID string
	URL       string
	URN       string
	LocalIP   net.IP
	// contains filtered or unexported fields
}

An IGDService is a specific service provided by an IGD.

func (*IGDService) AddPortMapping

func (s *IGDService) AddPortMapping(protocol Protocol, internalPort, externalPort int, description string, duration time.Duration) (int, error)

AddPortMapping adds a port mapping to the specified IGD service.

func (*IGDService) DeletePortMapping

func (s *IGDService) DeletePortMapping(protocol Protocol, externalPort int) error

DeletePortMapping deletes a port mapping from the specified IGD service.

func (*IGDService) GetExternalIPAddress

func (s *IGDService) GetExternalIPAddress() (net.IP, error)

GetExternalIPAddress queries the IGD service for its external IP address. Returns nil if the external IP address is invalid or undefined, along with any relevant errors

func (*IGDService) GetLocalIPAddress

func (s *IGDService) GetLocalIPAddress() net.IP

GetLocalIPAddress returns local IP address used to contact this service

func (*IGDService) ID

func (s *IGDService) ID() string

ID returns a unique ID for the servic

type Mapping

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

func (*Mapping) Address

func (m *Mapping) Address() Address

func (*Mapping) ExternalAddresses

func (m *Mapping) ExternalAddresses() []Address

func (*Mapping) GoString

func (m *Mapping) GoString() string

func (*Mapping) OnChanged

func (m *Mapping) OnChanged(subscribed MappingChangeSubscriber)

func (*Mapping) Protocol

func (m *Mapping) Protocol() Protocol

func (*Mapping) String

func (m *Mapping) String() string

type MappingChangeSubscriber

type MappingChangeSubscriber func(*Mapping, []Address, []Address)

type Protocol

type Protocol string
const (
	TCP Protocol = "TCP"
	UDP          = "UDP"
)

Jump to

Keyboard shortcuts

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