-
- Downloads
natpmp: fix out-of-order responses bug
This patch fixes a few issues with the way libnatpmp was used in DHTNet. The two most important ones are the following: 1) Each call to sendnewportmapping is now followed by a call to readResponse. This is important because libnatpmp expects the response to each request to be read before another request is sent; skipping a request can cause the responses to later requests to be incorrect. 2) All requests are now sent from the Asio thread. This wasn't the case before, and as a result the responses to requests made from different threads would sometimes get mixed up (e.g. if thread 1 sends request A and thread 2 sends request B, then thread 1 could end up reading the response to request B). The other (minor) issues are: 3) The readResponse function would return the NATPMP_ERR_SOCKETERROR error code when the MAX_READ_RETRIES limit was hit instead of NATPMP_TRYAGAIN, which made this case look identical to a poll error in the logs. The function would also sleep unnecessarily after the last iteration when the limit was reached. 4) The sendMappingRequest function tried to make up to MAX_READ_RETRIES calls to readResponse when it detected that it had gotten a response of the wrong type, but this doesn't work because libnatpmp doesn't allow reading multiple responses in a row and will simply return a NATPMP_ERR_NOPENDINGREQ error for each call after the first one. GitLab: #33 Change-Id: If8f0824eef1de601411c9e70bd33df46230a24f8
Loading
Please register or sign in to comment