From: <sv...@ww...> - 2004-12-18 10:54:57
|
Author: mkrose Date: 2004-12-18 02:54:46 -0800 (Sat, 18 Dec 2004) New Revision: 1404 Modified: trunk/CSP/SimNet/ClientServer.cpp trunk/CSP/SimNet/ClientServer.h Log: Small improvements to error handling and reporting of client-server connections. Also expose ExternalIp for Servers and deprecate it for Clients. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1404 Modified: trunk/CSP/SimNet/ClientServer.cpp =================================================================== --- trunk/CSP/SimNet/ClientServer.cpp 2004-12-18 10:50:33 UTC (rev 1403) +++ trunk/CSP/SimNet/ClientServer.cpp 2004-12-18 10:54:46 UTC (rev 1404) @@ -114,8 +114,8 @@ } void Server::onConnectionRequest(simdata::Ref<ConnectionRequest> const &msg, simdata::Ref<MessageQueue> const &queue) { - SIMNET_LOG(HANDSHAKE, DEBUG, "connection request " << *msg); - PeerId client_id = msg->getSource(); + SIMNET_LOG(HANDSHAKE, INFO, "connection request " << *msg); + const PeerId client_id = msg->getSource(); ConnectionData &connection_data = m_PendingConnections[client_id]; if (msg->incoming_bw() < 1000 || msg->outgoing_bw() < 1000) { SIMNET_LOG(HANDSHAKE, ERROR, "client reports very low bandwidth " << *msg); @@ -149,6 +149,10 @@ m_NetworkInterface->disconnectPeer(msg->getSource()); } +void Server::setExternalNode(NetworkNode const &external_node) { + m_NetworkInterface->setExternalNode(external_node); +} + Client::Client(NetworkNode const &bind, int inbound_bw, int outbound_bw): ClientServerBase(bind, false /*isServer*/, inbound_bw, outbound_bw), m_Connected(false) @@ -156,6 +160,7 @@ } Client::~Client() { + disconnectFromServer(true); } bool Client::connectToServer(NetworkNode const &server, double timeout) { @@ -189,9 +194,17 @@ if (!msg->has_success() || !msg->success() || !msg->has_client_id()) { if (msg->has_response()) { SIMNET_LOG(HANDSHAKE, ERROR, "connection failed: " << msg->response()); + } else { + SIMNET_LOG(HANDSHAKE, ERROR, "connection failed: " << *msg); } // TODO set m_Connected to indicate failure + return; } + if (msg->client_id() < 2) { + SIMNET_LOG(HANDSHAKE, ERROR, "connection failed: bad id assignment from server"); + // TODO set m_Connected to indicate failure + return; + } m_NetworkInterface->setClientId(msg->client_id()); Acknowledge::Ref ack = new Acknowledge(); ack->setReliable(); Modified: trunk/CSP/SimNet/ClientServer.h =================================================================== --- trunk/CSP/SimNet/ClientServer.h 2004-12-18 10:50:33 UTC (rev 1403) +++ trunk/CSP/SimNet/ClientServer.h 2004-12-18 10:54:46 UTC (rev 1404) @@ -216,6 +216,10 @@ * @param outbound_bw The maximum outbound bandwidth for this server (bytes/sec). */ Server(NetworkNode const &bind, int inbound_bw, int outbound_bw); + + /** See NetworkInterface::setExternalNode(). + */ + void setExternalNode(NetworkNode const &external_node); }; @@ -237,9 +241,12 @@ Client(NetworkNode const &bind, int inbound_bw, int outbound_bw); /** See NetworkInterface::setExternalNode(). + * @deprecated External node is now only used by Server. */ void setExternalNode(NetworkNode const &external_node); + /** Destroy the client. If connected to a server, queue disconnect messages. + */ virtual ~Client(); /** Connect to a server. @@ -255,7 +262,7 @@ /** Send a disconnect message to the server, and set the client state to disconnected. * - * @param immediate If fales, the disconnect message is queued as a reliable + * @param immediate If false, the disconnect message is queued as a reliable * packet. If true, two disconnect message are sent immediately via using * normal (unreliable) transport. The latter should only be used if it is * truly necessary to shut down the connection in a hurry, as there is no |