diff --git a/Config Default.yaml b/Config Default.yaml index 312b7a6..919c20d 100644 --- a/Config Default.yaml +++ b/Config Default.yaml @@ -1,5 +1,16 @@ LogFile: Log.txt + +# Listen defines all IP:Port combinations to listen on. If empty, it will listen on all IPs automatically on available ports. +# IPv6 must be in the form "[IPv6]:Port". This setting is only recommended to be set on servers. +Listen: [] + +# Count of workers to process incoming raw packets. Default 2. +ListenWorkers: 0 + +# AutoUpdateSeedList enables auto update of the seed list. AutoUpdateSeedList: true + +# Initial peer seed list. If AutoUpdateSeedList is enabled then any changes will be overwritten on update. SeedListVersion: 1 SeedList: - PublicKey: 02c490e4252bc7608fd55ddd9d7ca4a488ad152f3da6a6c2e9061f4c7e59f5b7f8 # 1.peernet.network @@ -12,3 +23,10 @@ SeedList: Address: ["178.18.241.68:112","[2a02:c206:2056:9660::1]:112"] - PublicKey: 03174f370cb6d6f361d0511565b6b456a82c3d16b53d6b63b227d76a4f0f2abd2c # 5.peernet.network Address: ["194.233.66.99:112","[2407:3640:2057:5241::1]:112"] + +# Connection settings +EnableUPnP: true # Enables support for UPnP. + +# PortForward specifies an external port that was manually forwarded by the user. All listening IPs must have that same port number forwarded! +# If this setting is invalid, it will prohibit other peers from connecting. If set, it automatically disables UPnP. +PortForward: 0 # Default not set. diff --git a/Config.go b/Config.go index 7b822f1..164c3f3 100644 --- a/Config.go +++ b/Config.go @@ -31,6 +31,13 @@ var config struct { SeedList []peerSeed `yaml:"SeedList"` AutoUpdateSeedList bool `yaml:"AutoUpdateSeedList"` SeedListVersion int `yaml:"SeedListVersion"` + + // Connection settings + EnableUPnP bool `yaml:"EnableUPnP"` // Enables support for UPnP. + + // PortForward specifies an external port that was manually forwarded by the user. All listening IPs must have that same port number forwarded! + // If this setting is invalid, it will prohibit other peers from connecting. If set, it automatically disables UPnP. + PortForward uint16 `yaml:"PortForward"` } // peerSeed is a singl peer entry from the config's seed list diff --git a/Connection.go b/Connection.go index c6b4ca7..dd83916 100644 --- a/Connection.go +++ b/Connection.go @@ -286,7 +286,11 @@ func setAnnouncementPorts(packet *PacketRaw, n *Network) { // UPnP: The port is forwarded automatically. // Manual override in config: The user can specify a (global) incoming port that must be open on all listening IPs. // This external port will be then passed onto other peers who will use it to connect. - portE := n.externalPort + portE := n.portExternal + + if config.PortForward > 0 { + portE = config.PortForward + } binary.LittleEndian.PutUint16(packet.Payload[15:17], portI) binary.LittleEndian.PutUint16(packet.Payload[17:19], portE) diff --git a/Network.go b/Network.go index 8f248fa..d311710 100644 --- a/Network.go +++ b/Network.go @@ -26,7 +26,7 @@ type Network struct { multicastSocket net.PacketConn // Multicast socket, IPv6 only. broadcastSocket net.PacketConn // Broadcast socket, IPv4 only. broadcastIPv4 []net.IP // Broadcast IPs, IPv4 only. - externalPort uint16 // External port. 0 if not known. + portExternal uint16 // External port. 0 if not known. isTerminated bool // If true, the network was signaled for termination terminateSignal chan interface{} // gets closed on termination signal, can be used in select via "case _ = <- network.terminateSignal:" sync.RWMutex // for sychronized closing @@ -237,8 +237,8 @@ func GetNetworks(networkType int) (networks []*Network) { } // GetListen returns connectivity information -func (network *Network) GetListen() (listen *net.UDPAddr, multicastIPv6 net.IP, broadcastIPv4 []net.IP, externalPort uint16) { - return network.address, network.multicastIP, network.broadcastIPv4, network.externalPort +func (network *Network) GetListen() (listen *net.UDPAddr, multicastIPv6 net.IP, broadcastIPv4 []net.IP, portExternal uint16) { + return network.address, network.multicastIP, network.broadcastIPv4, network.portExternal } // GetAdapterName returns the adapter name, if available diff --git a/README.md b/README.md index c756a79..a7dac0f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Peernet Core -The core library which is needed for any Peernet application. It provides connectivity to the network and all basic functions. For details about Peernet see https://peernet.org/. +The core library which is needed for any Peernet application. It provides connectivity to the network and all basic functions. For details about Peernet see https://peernet.org/. For the current technical roadmap and upcoming releases see the [Talk forum](https://talk.peernet.org/discussion/10/technical-roadmap). -Current version: 0.2 (early alpha) +Current version: 0.2 (pre alpha 2) Current development status: Initial connectivity works. DHT functionality is in development. @@ -53,15 +53,14 @@ lukechampine.com/blake3 ## Configuration -Peernet follows a "zeroconf" approach, meaning there is no manual configuration required. However, in certain cases such as providing root peers [1] that shall listen on a fixed IP and port, it is desirable to create a config file. +Peernet follows a "zeroconf" approach, meaning there is no manual configuration required. However, in certain cases such as providing root peers that shall listen on a fixed IP and port, it is desirable to create a config file. See inline documentation in the file [Config Default.yaml](Config%20Default.yaml). The name of the config file is passed to the function `LoadConfig`. If it does not exist, it will be created with the values from the file `Config Default.yaml`. It uses the YAML format. Any public/private keys in the config are hex encoded. Here are some notable settings: * `PrivateKey` The users Private Key hex encoded. The users public key is derived from it. -* `ListenWorkers` defines the count of concurrent workers processing packets (decrypting them and then taking action). Default 2. * `Listen` defines IP:Port combinations to listen on. If not specified, it will listen on all IPs. You can specify an IP but port 0 for auto port selection. IPv6 addresses must be in the format "[IPv6]:Port". -[1] Root peer = A peer operated by a known trusted entity. They allow to speed up the network including discovery of peers and data. +Root peer = A peer operated by a known trusted entity. They allow to speed up the network including discovery of peers and data. ### Private Key