Update start udp associate method

Rename func according to RFC.
Fix bad type of return.
Update arg type to get bnd addr and port.
pull/1857/head
myl7 2021-12-17 08:06:56 +08:00
parent de08f510be
commit 9061677c0e
No known key found for this signature in database
GPG Key ID: 04F1013B67177C88
3 changed files with 12 additions and 13 deletions

View File

@ -86,8 +86,8 @@ bool DHTConnectionSocksProxyImpl::startProxy(const std::string& host,
} }
// UDP associate // UDP associate
size_t i = ssize_t i = socket_->startUdpAssociate(listenAddr, listenPort,
socket_->startUdpProxy(listenAddr, listenPort, &bndAddr_, &bndPort_); std::make_pair(&bndAddr_, &bndPort_));
if (i < 0) { if (i < 0) {
return false; return false;
} }

View File

@ -109,10 +109,10 @@ char SocksProxySocket::authByUserpass(const std::string& user,
return res[1]; return res[1];
} }
size_t SocksProxySocket::startUdpProxy(const std::string& listenAddr, ssize_t
SocksProxySocket::startUdpAssociate(const std::string& listenAddr,
uint16_t listenPort, uint16_t listenPort,
std::string* bndAddrPtr, std::pair<std::string*, uint16_t*> bnd)
uint16_t* bndPortPtr)
{ {
std::stringstream req; std::stringstream req;
req << C_SOCKS_VER << C_CMD_UDP_ASSOCIATE << 0; req << C_SOCKS_VER << C_CMD_UDP_ASSOCIATE << 0;
@ -188,12 +188,12 @@ size_t SocksProxySocket::startUdpProxy(const std::string& listenAddr,
return -1; return -1;
} }
size_t i = bndAddrs_.size(); ssize_t i = static_cast<ssize_t>(bndAddrs_.size());
bndAddrs_.push_back(bndAddr); bndAddrs_.push_back(bndAddr);
bndPorts_.push_back(bndPort); bndPorts_.push_back(bndPort);
if (bndAddrPtr && bndPortPtr) { if (bnd.first && bnd.second) {
*bndAddrPtr = bndAddr; *(bnd.first) = bndAddr;
*bndPortPtr = bndPort; *(bnd.second) = bndPort;
} }
return i; return i;
} }

View File

@ -89,9 +89,8 @@ public:
// Leave listen host and port empty / 0 to indicate no receiving from proxy. // Leave listen host and port empty / 0 to indicate no receiving from proxy.
// Returns -1 when error, otherwise the index to get the bnd addr and port. // Returns -1 when error, otherwise the index to get the bnd addr and port.
// Set bndAddrPtr and bndPortPtr to directly get the result bnd addr and port. // Set bndAddrPtr and bndPortPtr to directly get the result bnd addr and port.
size_t startUdpProxy(const std::string& listenAddr, uint16_t listenPort, ssize_t startUdpAssociate(const std::string& listenAddr, uint16_t listenPort,
std::string* bndAddrPtr = nullptr, std::pair<std::string*, uint16_t*> bnd = {});
uint16_t* bndPortPtr = nullptr);
// Get bnd addr and port via index i. // Get bnd addr and port via index i.
// i is not checked and should be got from start*Proxy methods. // i is not checked and should be got from start*Proxy methods.