I am now trying to use Windows P2P native functions in my application to connect instances of it over the internet. For the testing, I've setup one application that uses PeerGraphCreate to establish a P2P graph and then registers some peer name using PeerPnrpRegister. I they register for messages using PeerGraphRegisterEvent and enter a loop while the application is listening for events in a thread. This side seems to work fine.
In the second application I open the graph using PeerGraphOpen which succeeds. I then resolve the peer name from the first app using PeerPnrpResolve. It returns two ipv6 addresses. However, when I feed any of those to the PeerGraphConnect function, it returns a HRESULT reading "Requested address is not valid in its context. I have no idea what's wrong, anyone would be so nice to provide a clue?
Here is the code of the second application for reference:
HRESULT hr = PeerGraphOpen( L"TestP2PGraph", L"DebugPeer", L"TestPeerDB", NULL, 0, NULL, &hGraph );
if( hr == S_OK || hr == PEER_S_GRAPH_DATA_CREATED )
if( SUCCEEDED( PeerPnrpStartup( PNRP_VERSION ) ) )
ULONG numEndpoints = 1;
hr = PeerPnrpResolve( L"0.TestBackgroundPeer", L"Global_", &numEndpoints, &endpointInfo );
if( SUCCEEDED( hr ) )
addr.dwSize = sizeof( PEER_ADDRESS );
addr.sin6 = *((SOCKADDR_IN6*)endpointInfo->ppAddresses);
hr = PeerGraphConnect( hGraph, NULL, &addr, &connection );
^^ this reads "Requested address is not valid in its context
I would really appreciate any hint of what can be wrong. The networking side of things is really not my strongest one so I may be missing something basic.
I got past this phase (somehow) but hit another roadblock - I describe it here: Failed to connect peer - invalid port settings?
]. It is as well possible that the problem is not solved at all, sadly. For reference the HRESULT code of the error described here is 0x80072741
but occurs only with wPort being set to zero in the original peer registration (as I describe in the linked question).