MCPcopy Create free account
hub / github.com/HumbleNet/HumbleNet / processMsg

Method processMsg

src/peer-server/p2p_connection.cpp:11–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10namespace humblenet {
11 ha_bool P2PSignalConnection::processMsg(const HumblePeer::Message* msg)
12 {
13 auto msgType = msg->message_type();
14
15 // we don't accept anything but HelloServer from a peer which hasn't sent one yet
16 if (!this->peerId) {
17 if (msgType != HumblePeer::MessageType::HelloServer) {
18 LOG_WARNING("Got non-HelloServer message (%s) from non-authenticated peer \"%s\"\n", HumblePeer::EnumNameMessageType(msgType), this->url.c_str());
19 // TODO: send error message
20 return false;
21 }
22 }
23
24 switch (msgType) {
25 case HumblePeer::MessageType::P2POffer:
26 {
27 auto p2p = reinterpret_cast<const HumblePeer::P2POffer*>(msg->message());
28 auto peer = p2p->peerId();
29
30 // look up target peer, send message on
31 // TODO: should ensure there's not already a negotiation going
32
33 bool emulated = (p2p->flags() & 0x1);
34
35 LOG_INFO("P2POffer from peer %u (%s) to peer %u", this->peerId, url.c_str(), peer);
36 if (emulated) {
37 LOG_INFO(", emulated connections not allowed\n");
38 // TODO: better error message
39 sendNoSuchPeer(this, peer);
40 return true;
41 }
42
43 auto it = game->peers.find(peer);
44 if (it == game->peers.end()) {
45 LOG_WARNING(", no such peer\n");
46 sendNoSuchPeer(this, peer);
47 } else {
48 P2PSignalConnection *otherPeer = it->second;
49 assert(otherPeer != NULL);
50
51 // if not emulated check if otherPeer supports WebRTC
52 // to avoid unnecessary round trip
53 if (!emulated && !otherPeer->webRTCsupport) {
54 // webrtc connections not supported
55 LOG_INFO("(%s), refusing because target doesn't support WebRTC\n", otherPeer->url.c_str());
56 sendPeerRefused(this, peer);
57 return true;
58 }
59
60 LOG_INFO("(%s)\n", otherPeer->url.c_str());
61
62 // TODO: should check that it doesn't exist already
63 this->connectedPeers.insert(otherPeer);
64
65 // set peer id to originator so target knows who wants to connect
66 sendP2PConnect(otherPeer, this->peerId, p2p->flags(), p2p->offer()->c_str());
67 }
68

Callers 1

p2pSignalProcessFunction · 0.80

Calls 15

sendNoSuchPeerFunction · 0.85
sendPeerRefusedFunction · 0.85
sendP2PConnectFunction · 0.85
sendP2PResponseFunction · 0.85
sendICECandidateFunction · 0.85
sendHelloClientFunction · 0.85
sendP2PRelayDataFunction · 0.85
erase_valueFunction · 0.85
sendAliasResolvedFunction · 0.85
c_strMethod · 0.80
findMethod · 0.80
getVerifiedGameMethod · 0.80

Tested by

no test coverage detected