diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2020-11-24 12:40:03 +0100 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2021-03-01 12:57:01 +0100 |
commit | 7c224fdac4699a2c4953b33ab423f9cddbf95cf7 (patch) | |
tree | 4902d88f187f5482d04e414ef927cfb6bdc6d4f4 /src/net.cpp | |
parent | 1f75a653dd3b24ba2e4383bf951a6e5a3d5ccbcf (diff) |
net: isolate the protocol-agnostic part of CConnman::AcceptConnection()
Isolate the second half of `CConnman::AcceptConnection()` into a new
separate method, which could be reused if we accept incoming connections
by other means than `accept()` (first half of
`CConnman::AcceptConnection()`).
Diffstat (limited to 'src/net.cpp')
-rw-r--r-- | src/net.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp index a0072800e2..6109fc4e5a 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1005,8 +1005,6 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { socklen_t len = sizeof(sockaddr); SOCKET hSocket = accept(hListenSocket.socket, (struct sockaddr*)&sockaddr, &len); CAddress addr; - int nInbound = 0; - int nMaxInbound = nMaxConnections - m_max_outbound; if (hSocket == INVALID_SOCKET) { const int nErr = WSAGetLastError(); @@ -1024,6 +1022,18 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { NetPermissionFlags permissionFlags = NetPermissionFlags::PF_NONE; hListenSocket.AddSocketPermissionFlags(permissionFlags); + + CreateNodeFromAcceptedSocket(hSocket, permissionFlags, addr_bind, addr); +} + +void CConnman::CreateNodeFromAcceptedSocket(SOCKET hSocket, + NetPermissionFlags permissionFlags, + const CAddress& addr_bind, + const CAddress& addr) +{ + int nInbound = 0; + int nMaxInbound = nMaxConnections - m_max_outbound; + AddWhitelistPermissionFlags(permissionFlags, addr); if (NetPermissions::HasFlag(permissionFlags, NetPermissionFlags::PF_ISIMPLICIT)) { NetPermissions::ClearFlag(permissionFlags, PF_ISIMPLICIT); |