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
size_t i =
socket_->startUdpProxy(listenAddr, listenPort, &bndAddr_, &bndPort_);
ssize_t i = socket_->startUdpAssociate(listenAddr, listenPort,
std::make_pair(&bndAddr_, &bndPort_));
if (i < 0) {
return false;
}

View File

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

View File

@ -89,9 +89,8 @@ public:
// 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.
// Set bndAddrPtr and bndPortPtr to directly get the result bnd addr and port.
size_t startUdpProxy(const std::string& listenAddr, uint16_t listenPort,
std::string* bndAddrPtr = nullptr,
uint16_t* bndPortPtr = nullptr);
ssize_t startUdpAssociate(const std::string& listenAddr, uint16_t listenPort,
std::pair<std::string*, uint16_t*> bnd = {});
// Get bnd addr and port via index i.
// i is not checked and should be got from start*Proxy methods.