Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
ssh → SSH
stun server → STUN server
try → attempt
turn server → TURN server
UPNP → UPnP

Change-Id: Ia31a3baae908850a7e99d50128447f2eb9113df1
  • Loading branch information
ovari committed Nov 27, 2024
1 parent bae4391 commit 58df28d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 43 deletions.
6 changes: 3 additions & 3 deletions include/turn_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ class TurnCache : public std::enable_shared_from_this<TurnCache>
*/
std::atomic_bool isRefreshing_ {false};
/**
* This will cache the turn server resolution each time we launch
* This will cache the TURN server resolution each time we launch
* Jami, or for each connectivityChange()
*/
void testTurn(IpAddr server);
std::unique_ptr<TurnTransport> testTurnV4_;
std::unique_ptr<TurnTransport> testTurnV6_;

// Used to detect if a turn server is down.
// Used to detect if a TURN server is down.
void refreshTurnDelay(bool scheduleNext);
std::chrono::seconds turnRefreshDelay_ {std::chrono::seconds(10)};

// Store resoved turn addresses
// Store resoved TURN addresses
mutable std::mutex cachedTurnMutex_ {};
std::unique_ptr<IpAddr> cacheTurnV4_ {};
std::unique_ptr<IpAddr> cacheTurnV6_ {};
Expand Down
46 changes: 23 additions & 23 deletions src/ice_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class IceTransport::Impl
void addServerReflexiveCandidates(const std::vector<std::pair<IpAddr, IpAddr>>& addrList);
// Generate server reflexive candidates using the published (DHT/Account) address
std::vector<std::pair<IpAddr, IpAddr>> setupGenericReflexiveCandidates();
// Generate server reflexive candidates using UPNP mappings.
// Generate server reflexive candidates using UPnP mappings.
std::vector<std::pair<IpAddr, IpAddr>> setupUpnpReflexiveCandidates();
void setDefaultRemoteAddress(unsigned comp_id, const IpAddr& addr);
IpAddr getDefaultRemoteAddress(unsigned comp_id) const;
Expand Down Expand Up @@ -259,7 +259,7 @@ class IceTransport::Impl
//==============================================================================

/**
* Add stun/turn configuration or default host as candidates
* Add STUN/TURN configuration or default host as candidates
*/

static void
Expand Down Expand Up @@ -288,7 +288,7 @@ add_stun_server(pj_pool_t& pool, pj_ice_strans_cfg& cfg, const StunServerInfo& i
stun.cfg.max_pkt_size = STUN_MAX_PACKET_SIZE;
stun.conn_type = cfg.stun.conn_type;
if (logger)
logger->debug("Added stun server '{}', port {}", pj_strbuf(&stun.server), stun.port);
logger->debug("Added STUN server '{}', port {}", pj_strbuf(&stun.server), stun.port);
}

static void
Expand Down Expand Up @@ -330,7 +330,7 @@ add_turn_server(pj_pool_t& pool, pj_ice_strans_cfg& cfg, const TurnServerInfo& i
info.password.size());
}
if (logger)
logger->debug("Added turn server '{}', port {}", pj_strbuf(&turn.server), turn.port);
logger->debug("Added TURN server '{}', port {}", pj_strbuf(&turn.server), turn.port);
}

//==============================================================================
Expand Down Expand Up @@ -455,18 +455,18 @@ IceTransport::Impl::initIceInstance(const IceTransportOptions& options)
if (not pool_)
throw std::runtime_error("pj_pool_create() failed");

// Note: For server reflexive candidates, UPNP mappings will
// Note: For server reflexive candidates, UPnP mappings will
// be used if available. Then, the public address learnt during
// the account registration process will be added only if it
// differs from the UPNP public address.
// Also note that UPNP candidates should be added first in order
// differs from the UPnP public address.
// Also note that UPnP candidates should be added first in order
// to have a higher priority when performing the connectivity
// checks.
// STUN configs layout:
// - index 0 : host IPv4
// - index 1 : host IPv6
// - index 2 : upnp/generic srflx IPv4.
// - index 3 : generic srflx (if upnp exists and different)
// - index 2 : UPnP/generic srflx IPv4
// - index 3 : generic srflx (if UPnP exists and different)

config_.stun_tp_cnt = 0;

Expand All @@ -482,15 +482,15 @@ IceTransport::Impl::initIceInstance(const IceTransportOptions& options)
if (not upnpSrflxCand.empty()) {
addServerReflexiveCandidates(upnpSrflxCand);
// if (logger_)
// logger_->debug("[ice:{}] Added UPNP srflx candidates:", fmt::ptr(this));
// logger_->debug("[ice:{}] Added UPnP srflx candidates:", fmt::ptr(this));
}
}

auto genericSrflxCand = setupGenericReflexiveCandidates();

if (not genericSrflxCand.empty()) {
// Generic srflx candidates will be added only if different
// from upnp candidates.
// from UPnP candidates.
if (upnpSrflxCand.empty()
or (upnpSrflxCand[0].second.toString() != genericSrflxCand[0].second.toString())) {
addServerReflexiveCandidates(genericSrflxCand);
Expand Down Expand Up @@ -953,7 +953,7 @@ IceTransport::Impl::requestUpnpMappings()
pendingState_ = state;
}

// Request upnp mapping for each component.
// Request UPnP mapping for each component.
for (unsigned id = 1; id <= compCount_; id++) {
// Set port number to 0 to get any available port.
Mapping requestedMap(portType);
Expand All @@ -973,7 +973,7 @@ IceTransport::Impl::requestUpnpMappings()
} else if (mapPtr->getState() == MappingState::FAILED) {
state->failed = true;
if (l)
l->error("UPNP mapping failed: {:s}",
l->error("UPnP mapping failed: {:s}",
mapPtr->toString(true));
}
state->cv.notify_all();
Expand All @@ -996,7 +996,7 @@ IceTransport::Impl::requestUpnpMappings()
// Check the number of mappings
if (state->failed || state->mappings.size() != compCount_) {
if (logger_)
logger_->error("[ice:{}] UPNP mapping failed: expected {:d} mappings, got {:d}",
logger_->error("[ice:{}] UPnP mapping failed: expected {:d} mappings, got {:d}",
fmt::ptr(this),
compCount_,
state->mappings.size());
Expand All @@ -1007,7 +1007,7 @@ IceTransport::Impl::requestUpnpMappings()
} else {
for (auto& map : state->mappings) {
if(logger_)
logger_->debug("[ice:{}] UPNP mapping {:s} successfully allocated\n",
logger_->debug("[ice:{}] UPnP mapping {:s} successfully allocated\n",
fmt::ptr(this),
map.second->toString(true));
upnpMappings_.emplace(map.first, *map.second);
Expand Down Expand Up @@ -1039,7 +1039,7 @@ IceTransport::Impl::addServerReflexiveCandidates(
return;
}

// Add config for server reflexive candidates (UPNP or from DHT).
// Add config for server reflexive candidates (UPnP or from DHT).
if (not addStunConfig(pj_AF_INET()))
return;

Expand Down Expand Up @@ -1115,7 +1115,7 @@ IceTransport::Impl::setupGenericReflexiveCandidates()
std::vector<std::pair<IpAddr, IpAddr>>
IceTransport::Impl::setupUpnpReflexiveCandidates()
{
// Add UPNP server reflexive candidates if available.
// Add UPnP server reflexive candidates if available.
if (not hasUpnp())
return {};

Expand Down Expand Up @@ -1374,7 +1374,7 @@ IceTransport::startIce(const SDP& sdp)

if (not isInitialized()) {
if (pimpl_->logger_)
pimpl_->logger_->error(FMT_STRING("[ice:{}] not initialized transport"), fmt::ptr(pimpl_));
pimpl_->logger_->error(FMT_STRING("[ice:{}] Uninitialized transport"), fmt::ptr(pimpl_));
pimpl_->is_stopped_ = true;
return false;
}
Expand All @@ -1389,7 +1389,7 @@ IceTransport::startIce(const SDP& sdp)
}

if (pimpl_->logger_)
pimpl_->logger_->debug("[ice:{}] negotiation starting ({:u} remote candidates)",
pimpl_->logger_->debug("[ice:{}] Negotiation starting ({:u} remote candidates)",
fmt::ptr(pimpl_), sdp.candidates.size());
pj_str_t ufrag, pwd;

Expand Down Expand Up @@ -1626,7 +1626,7 @@ IceTransport::parseIceAttributeLine(unsigned streamIdx,
cand.type = PJ_ICE_CAND_TYPE_RELAYED;
else {
if (pimpl_->logger_)
pimpl_->logger_->warn("[ice:{}] invalid remote candidate type '{:s}'", fmt::ptr(pimpl_), type);
pimpl_->logger_->warn("[ice:{}] Invalid remote candidate type '{:s}'", fmt::ptr(pimpl_), type);
return false;
}

Expand All @@ -1639,7 +1639,7 @@ IceTransport::parseIceAttributeLine(unsigned streamIdx,
cand.transport = PJ_CAND_TCP_SO;
else {
if (pimpl_->logger_)
pimpl_->logger_->warn("[ice:{}] invalid transport type type '{:s}'", fmt::ptr(pimpl_), tcp_type);
pimpl_->logger_->warn("[ice:{}] Invalid transport type type '{:s}'", fmt::ptr(pimpl_), tcp_type);
return false;
}
} else {
Expand Down Expand Up @@ -1667,7 +1667,7 @@ IceTransport::parseIceAttributeLine(unsigned streamIdx,
status = pj_sockaddr_set_str_addr(af, &cand.addr, &tmpaddr);
if (status != PJ_SUCCESS) {
if (pimpl_->logger_)
pimpl_->logger_->warn("[ice:{}] invalid IP address '{:s}'", fmt::ptr(pimpl_), ipaddr);
pimpl_->logger_->warn("[ice:{}] Invalid IP address '{:s}'", fmt::ptr(pimpl_), ipaddr);
return false;
}

Expand Down Expand Up @@ -1777,7 +1777,7 @@ IceTransport::send(unsigned compId, const unsigned char* buf, size_t len)
errno = EAGAIN;
} else {
if (pimpl_->logger_)
pimpl_->logger_->error("[ice:{}] ice send failed: {:s}", fmt::ptr(pimpl_), sip_utils::sip_strerror(status));
pimpl_->logger_->error("[ice:{}] ICE send failed: {:s}", fmt::ptr(pimpl_), sip_utils::sip_strerror(status));
errno = EIO;
}
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/turn/turn_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ TurnTransport::TurnTransport(const TurnTransportParams& params, std::function<vo
if (!server.getPort())
server.setPort(PJ_STUN_PORT);
if (server.isUnspecified())
throw std::invalid_argument("invalid turn server address");
throw std::invalid_argument("Invalid TURN server address");
pimpl_->settings = params;
// PJSIP memory pool
pj_caching_pool_init(&pimpl_->poolCache, &pj_pool_factory_default_policy, 0);
Expand Down
8 changes: 4 additions & 4 deletions src/upnp/protocol/pupnp/pupnp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ errorOnResponse(IXML_Document* doc, const std::shared_ptr<dht::log::Logger>& log
return false;
}

// UPNP class implementation
// UPnP class implementation

PUPnP::PUPnP(const std::shared_ptr<asio::io_context>& ctx, const std::shared_ptr<dht::log::Logger>& logger)
: UPnPProtocol(logger), ioContext(ctx), searchForIgdTimer_(*ctx)
Expand Down Expand Up @@ -170,7 +170,7 @@ PUPnP::registerClient()
{
assert(not clientRegistered_);

// Register Upnp control point.
// Register UPnP control point.
int upnp_err = UpnpRegisterClient(ctrlPtCallback, this, &ctrlptHandle_);
if (upnp_err != UPNP_E_SUCCESS) {
if (logger_) logger_->error("PUPnP: Unable to register client: {}", UpnpGetErrorMessage(upnp_err));
Expand Down Expand Up @@ -347,7 +347,7 @@ PUPnP::searchForIgd()
searchForDevices();
observer_->onIgdDiscoveryStarted();
} else {
if (logger_) logger_->warn("PUPnP: PUPNP not fully setup. Skipping the IGD search");
if (logger_) logger_->warn("PUPnP: PUPnP not fully setup. Skipping the IGD search");
}
}

Expand Down Expand Up @@ -1611,7 +1611,7 @@ PUPnP::actionAddPortMapping(const Mapping& mapping)
auto errorCode = getFirstDocItem(response.get(), "errorCode");
if (not errorCode.empty()) {
success = false;
// Try to get the error description.
// Attempt to get the error description.
std::string errorDescription;
if (response) {
errorDescription = getFirstDocItem(response.get(), "errorDescription");
Expand Down
6 changes: 3 additions & 3 deletions src/upnp/protocol/pupnp/pupnp.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ class PUPnP : public UPnPProtocol
// Unregister the client
void unregisterClient();

// Start search for UPNP devices
// Start search for UPnP devices
void searchForDevices();

// Start search for UPNP device in a different thread
// Start search for UPnP device in a different thread
void searchForDeviceAsync(const std::string& deviceType);

// Return true if it has at least one valid IGD.
Expand Down Expand Up @@ -249,7 +249,7 @@ class PUPnP : public UPnPProtocol
IpAddr hostAddress_ {};

// Calls from other threads that does not need synchronous access are
// rescheduled on the UPNP private queue. This will avoid the need to
// rescheduled on the UPnP private queue. This will avoid the need to
// protect most of the data members of this class.
// For some internal members (namely the validIgdList and the hostAddress)
// that need to be synchronously accessed, are protected by this mutex.
Expand Down
8 changes: 4 additions & 4 deletions src/upnp/upnp_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ UPnPContext::shutdown()

ctx->post([&, this] { shutdown(cv); });

if (logger_) logger_->debug("Waiting for shutdown ...");
if (logger_) logger_->debug("Waiting for shutdown");

if (cv.wait_for(lk, std::chrono::seconds(30), [this] { return shutdownComplete_; })) {
if (logger_) logger_->debug("Shutdown completed");
Expand Down Expand Up @@ -163,7 +163,7 @@ UPnPContext::startUpnp()
{
assert(not controllerList_.empty());

if (logger_) logger_->debug("Starting UPNP context");
if (logger_) logger_->debug("Starting UPnP context");

// Request a new IGD search.
for (auto const& [_, protocol] : protocolList_) {
Expand Down Expand Up @@ -329,7 +329,7 @@ UPnPContext::reserveMapping(Mapping& requestedMap)
if (logger_) logger_->debug("Desired port is not set, will provide the first available port for [{}]",
requestedMap.getTypeStr());
} else {
if (logger_) logger_->debug("Try to find mapping for port {:d} [{}]", desiredPort, requestedMap.getTypeStr());
if (logger_) logger_->debug("Attempt to find mapping for port {:d} [{}]", desiredPort, requestedMap.getTypeStr());
}

Mapping::sharedPtr_t mapRes;
Expand Down Expand Up @@ -594,7 +594,7 @@ UPnPContext::updateCurrentIgd()
if (not igd->isValid())
continue;

// Prefer NAT-PMP over PUPNP.
// Prefer NAT-PMP over PUPnP.
if (currentIgd_ and igd->getProtocol() != NatProtocolType::NAT_PMP)
continue;

Expand Down
8 changes: 4 additions & 4 deletions tools/dhtnet_crtmgr/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int create_yaml_config(std::filesystem::path file, std::filesystem::path certifi
yaml_file << "\n# When verbose is set to true, the server logs all incoming connections\n";
yaml_file << "verbose: false\n";

yaml_file << "\n# If true, will send request to use UPNP if available\n";
yaml_file << "\n# If true, will send request to use UPnP if available\n";
yaml_file << "enable_upnp: true\n";

yaml_file << "\n# On server, identities are saved in /etc/dhtnet/id/\n";
Expand Down Expand Up @@ -168,7 +168,7 @@ int configure_ssh_config(std::filesystem::path yaml_config)
}
std::filesystem::path ssh_dir = home_dir / ".ssh";
if (!std::filesystem::exists(ssh_dir)) {
fmt::print(stderr, "Error: {} folder doesn't exist. Install and configure ssh client first.\n", ssh_dir);
fmt::print(stderr, "Error: {} folder doesn't exist. Install and configure SSH client first.\n", ssh_dir);
return 1;
}
std::filesystem::path ssh_config = ssh_dir / "config";
Expand All @@ -177,7 +177,7 @@ int configure_ssh_config(std::filesystem::path yaml_config)
std::string line;
while (std::getline(ssh_file, line)) {
if (line.find("Host dnc") != std::string::npos) {
Log("Info: dnc configuration already exists in ssh config. File is left untouched\n");
Log("Info: dnc configuration already exists in SSH config. File is left untouched\n");
return 0;
}
}
Expand All @@ -189,7 +189,7 @@ int configure_ssh_config(std::filesystem::path yaml_config)
ssh_file.close();
Log("SSH configuration added to {}\n", ssh_config);
} else {
fmt::print(stderr, "Error: Unable to open ssh config file.\n");
fmt::print(stderr, "Error: Unable to open SSH config file.\n");
return 1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion tools/dnc/dnc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ turn_realm: "sfl"
# When verbose is set to true, the server logs all incoming connections
verbose: false

# If true, will send request to use UPNP if available
# If true, will send request to use UPnP if available
enable_upnp: true

# On server, identities are saved in /etc/dhtnet/id/
Expand Down

0 comments on commit 58df28d

Please sign in to comment.