King should open ames ports via NAT-PMP#3261
Conversation
(Not yet hooked up to anything.)
There was a TODO in runShips about how the different layers of the RIO environment had to be changed, so that there was a layer between KingEnv and PierEnv for things shared between individual Piers, but which weren't used outside of any PierEnv. This addresses those TODOs by creating RunningEnv, which for now just owns MultiEyreApi and makes it so we don't have to pass the entire thing around explicitly. The IP handling stuff will go in RunningEnv in a following patch.
This sets up a separate thread to handle scheduling of lease renewals.
Tested with a comet trying to receive traffic from a planet in the cloud. (h/t ~master-morzod)
Also: error checking.
|
How widely supported is NATPMP as opposed to PCP? It appears this has been a successor protocol since 2013: https://tools.ietf.org/html/rfc6887 |
|
I'm not aware of anyone that uses PCP. It's either NAT-PMP, or the older XML based UPnP IGD protocol. A quick peek at a two torrent clients show that neither supports PCP. |
|
Friendly ping. |
pilfer-pandex
left a comment
There was a problem hiding this comment.
Lots of comments, mostly nits.
| ":", err, ", disabling NAT-PMP") | ||
| loopErr q | ||
| Right _ -> do | ||
| let filteredPort = filterPort p nextRenew |
There was a problem hiding this comment.
Does this amount to quadratic behavior?
|
Did most of the nits plus separated out the TQueue from the heap. The things I left unaddressed and unresolved were things I don't understand the point you're trying to make. |
| Left err -> do | ||
| ip <- likelyIPAddress | ||
| case ip of | ||
| Just (192, 168, c, d) -> do |
There was a problem hiding this comment.
Yeah. IPv4 allocates two blocks for private networks: 10/8 and 192.168/16. You handle only the second, but we should be handling both.
| typedef struct { | ||
| uint16_t type; /* NATPMP_RESPTYPE_* */ | ||
| uint16_t resultcode; /* NAT-PMP response code */ | ||
| uint32_t epoch; /* Seconds since start of epoch */ | ||
| union { | ||
| struct { | ||
| //in_addr_t addr; | ||
| struct in_addr addr; | ||
| } publicaddress; | ||
| struct { | ||
| uint16_t privateport; | ||
| uint16_t mappedpublicport; | ||
| uint32_t lifetime; | ||
| } newportmapping; | ||
| } pnu; | ||
| } natpmpresp_t; |
There was a problem hiding this comment.
a language that has a proper datatype description language
King should open ames ports via NAT-PMP
Same as urbit/urbit#3261 but for vere. From what I can tell this NAT-PMP stuff is fairly well supported by routers, works on my machine at least.
Same as urbit/urbit#3261 but for vere. From what I can tell this NAT-PMP stuff is fairly well supported by routers, works on my machine at least.
This vendors libnatpmp and writes Haskell bindings to it. It then adds support to king haskell to use this to open up the ames port to the world. This way, people behind consumer grade residential routers should be able to get direct routes.
This is on by default, but can be disabled in hosting contexts with
--no-port-forwarding.This patch also does a minor reorganization of the RIO environments, adding a middle "Running" environment between KingEnv and PierEnv, address some TODOs. I did this since this was the natural place to also put a PortControllerApi.
@joemfb: concept, along with bindings.c, the one new C file I added (though it's mostly code adapted from libnatpmp's test suite).
@pilfer-pandex: all the haskell code here. This is the first time I've written any hs2c or used the FFI.