mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
allow connect-method config var
This commit is contained in:
parent
1de3b1d9df
commit
81d1f43ad0
@ -22,7 +22,7 @@ class ConnectionRepository(
|
|||||||
taskPriority = -30
|
taskPriority = -30
|
||||||
|
|
||||||
CM_HTTP=0
|
CM_HTTP=0
|
||||||
CM_NSPR=1
|
CM_NET=1
|
||||||
CM_NATIVE=2
|
CM_NATIVE=2
|
||||||
|
|
||||||
|
|
||||||
@ -41,28 +41,46 @@ class ConnectionRepository(
|
|||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
if hasattr(self, 'setVerbose'):
|
|
||||||
if self.config.GetBool('verbose-repository'):
|
if self.config.GetBool('verbose-repository'):
|
||||||
self.setVerbose(1)
|
self.setVerbose(1)
|
||||||
|
|
||||||
# Set this to 'http' to establish a connection to the server
|
# Set this to 'http' to establish a connection to the server
|
||||||
# using the HTTPClient interface, which ultimately uses the
|
# using the HTTPClient interface, which ultimately uses the
|
||||||
# OpenSSL socket library (even though SSL is not involved).
|
# OpenSSL socket library (even though SSL is not involved).
|
||||||
# This is not as robust a socket library as NSPR's, but the
|
# This is not as robust a socket library as NET's, but the
|
||||||
# HTTPClient interface does a good job of negotiating the
|
# HTTPClient interface does a good job of negotiating the
|
||||||
# connection over an HTTP proxy if one is in use.
|
# connection over an HTTP proxy if one is in use.
|
||||||
#
|
#
|
||||||
# Set it to 'nspr' to use Panda's net interface
|
# Set it to 'net' to use Panda's net interface
|
||||||
# (e.g. QueuedConnectionManager, etc.) to establish the
|
# (e.g. QueuedConnectionManager, etc.) to establish the
|
||||||
# connection, which ultimately uses the NSPR socket library.
|
# connection. This is a higher-level layer build on top of
|
||||||
# This is a much better socket library, but it may be more
|
# the low-level "native net" library. There is no support for
|
||||||
# than you need for most applications; and there is no support
|
# proxies. This is a good, general choice.
|
||||||
# for proxies.
|
|
||||||
#
|
#
|
||||||
# Set it to 'default' to use the HTTPClient interface if a
|
# Set it to 'native' to use Panda's low-level native net
|
||||||
# proxy is in place, but the NSPR interface if we don't have a
|
# interface directly. This is much faster than either http or
|
||||||
# proxy.
|
# net for high-bandwidth (e.g. server) applications, but it
|
||||||
self.connectMethod=connectMethod
|
# doesn't support the simulated delay via the start_delay()
|
||||||
|
# call.
|
||||||
|
#
|
||||||
|
# Set it to 'default' to use an appropriate interface
|
||||||
|
# according to the type of ConnectionRepository we are
|
||||||
|
# creating.
|
||||||
|
userConnectMethod = self.config.GetString('connect-method', 'default')
|
||||||
|
if userConnectMethod == 'http':
|
||||||
|
connectMethod = self.CM_HTTP
|
||||||
|
elif userConnectMethod == 'net':
|
||||||
|
connectMethod = self.CM_NET
|
||||||
|
elif userConnectMethod == 'native':
|
||||||
|
connectMethod = self.CM_NATIVE
|
||||||
|
|
||||||
|
self.connectMethod = connectMethod
|
||||||
|
if self.connectMethod == self.CM_HTTP:
|
||||||
|
self.notify.info("Using connect method 'http'")
|
||||||
|
elif self.connectMethod == self.CM_NET:
|
||||||
|
self.notify.info("Using connect method 'net'")
|
||||||
|
elif self.connectMethod == self.CM_NATIVE:
|
||||||
|
self.notify.info("Using connect method 'native'")
|
||||||
|
|
||||||
self.connectHttp = None
|
self.connectHttp = None
|
||||||
self.http = None
|
self.http = None
|
||||||
@ -375,7 +393,7 @@ class ConnectionRepository(
|
|||||||
else:
|
else:
|
||||||
self.notify.info("Connecting to gameserver directly (no proxy).")
|
self.notify.info("Connecting to gameserver directly (no proxy).")
|
||||||
|
|
||||||
#Redefine the connection to http or nspr in the default case
|
#Redefine the connection to http or net in the default case
|
||||||
|
|
||||||
self.bootedIndex = None
|
self.bootedIndex = None
|
||||||
self.bootedText = None
|
self.bootedText = None
|
||||||
@ -393,11 +411,11 @@ class ConnectionRepository(
|
|||||||
ch, serverList, 0,
|
ch, serverList, 0,
|
||||||
successCallback, successArgs,
|
successCallback, successArgs,
|
||||||
failureCallback, failureArgs)
|
failureCallback, failureArgs)
|
||||||
elif self.connectMethod == self.CM_NSPR or (not hasattr(self,"connectNative")):
|
elif self.connectMethod == self.CM_NET or (not hasattr(self,"connectNative")):
|
||||||
# Try each of the servers in turn.
|
# Try each of the servers in turn.
|
||||||
for url in serverList:
|
for url in serverList:
|
||||||
self.notify.info("Connecting to %s via NSPR interface." % (url.cStr()))
|
self.notify.info("Connecting to %s via NET interface." % (url.cStr()))
|
||||||
if self.tryConnectNspr(url):
|
if self.tryConnectNet(url):
|
||||||
self.startReaderPollTask()
|
self.startReaderPollTask()
|
||||||
if successCallback:
|
if successCallback:
|
||||||
successCallback(*successArgs)
|
successCallback(*successArgs)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#begin lib_target
|
#begin lib_target
|
||||||
#define BUILD_TARGET $[HAVE_PYTHON]
|
#define BUILD_TARGET $[HAVE_PYTHON]
|
||||||
#define USE_PACKAGES openssl nspr native_net
|
#define USE_PACKAGES openssl native_net net
|
||||||
|
|
||||||
#define TARGET distributed
|
#define TARGET distributed
|
||||||
#define LOCAL_LIBS \
|
#define LOCAL_LIBS \
|
||||||
|
@ -79,7 +79,7 @@ set_python_repository(PyObject *python_repository) {
|
|||||||
}
|
}
|
||||||
#endif // HAVE_PYTHON
|
#endif // HAVE_PYTHON
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CConnectionRepository::get_qcm
|
// Function: CConnectionRepository::get_qcm
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -90,9 +90,9 @@ INLINE QueuedConnectionManager &CConnectionRepository::
|
|||||||
get_qcm() {
|
get_qcm() {
|
||||||
return _qcm;
|
return _qcm;
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CConnectionRepository::get_cw
|
// Function: CConnectionRepository::get_cw
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -104,9 +104,9 @@ get_cw() {
|
|||||||
return _cw;
|
return _cw;
|
||||||
}
|
}
|
||||||
INLINE ConnectionWriter &get_cw();
|
INLINE ConnectionWriter &get_cw();
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CConnectionRepository::get_qcr
|
// Function: CConnectionRepository::get_qcr
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -118,7 +118,7 @@ get_qcr() {
|
|||||||
return _qcr;
|
return _qcr;
|
||||||
}
|
}
|
||||||
INLINE QueuedConnectionReader &get_qcr();
|
INLINE QueuedConnectionReader &get_qcr();
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef WANT_NATIVE_NET
|
#ifdef WANT_NATIVE_NET
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -49,7 +49,7 @@ CConnectionRepository(bool has_owner_view) :
|
|||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
_http_conn(NULL),
|
_http_conn(NULL),
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
_cw(&_qcm, 0),
|
_cw(&_qcm, 0),
|
||||||
_qcr(&_qcm, 0),
|
_qcr(&_qcm, 0),
|
||||||
#endif
|
#endif
|
||||||
@ -65,7 +65,7 @@ CConnectionRepository(bool has_owner_view) :
|
|||||||
_msg_type(0),
|
_msg_type(0),
|
||||||
_has_owner_view(has_owner_view)
|
_has_owner_view(has_owner_view)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_NSPR) && defined(SIMULATE_NETWORK_DELAY)
|
#if defined(HAVE_NET) && defined(SIMULATE_NETWORK_DELAY)
|
||||||
if (min_lag != 0.0 || max_lag != 0.0) {
|
if (min_lag != 0.0 || max_lag != 0.0) {
|
||||||
_qcr.start_delay(min_lag, max_lag);
|
_qcr.start_delay(min_lag, max_lag);
|
||||||
}
|
}
|
||||||
@ -119,38 +119,38 @@ get_stream() {
|
|||||||
#endif // HAVE_OPENSSL
|
#endif // HAVE_OPENSSL
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CConnectionRepository::try_connect_nspr
|
// Function: CConnectionRepository::try_connect_net
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: Uses NSPR to try to connect to the server and port
|
// Description: Uses Panda's "net" library to try to connect to the
|
||||||
// named in the indicated URL. Returns true if
|
// server and port named in the indicated URL. Returns
|
||||||
// successful, false otherwise.
|
// true if successful, false otherwise.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool CConnectionRepository::
|
bool CConnectionRepository::
|
||||||
try_connect_nspr(const URLSpec &url) {
|
try_connect_net(const URLSpec &url) {
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
_nspr_conn =
|
_net_conn =
|
||||||
_qcm.open_TCP_client_connection(url.get_server(), url.get_port(),
|
_qcm.open_TCP_client_connection(url.get_server(), url.get_port(),
|
||||||
game_server_timeout_ms);
|
game_server_timeout_ms);
|
||||||
|
|
||||||
if (_nspr_conn != (Connection *)NULL) {
|
if (_net_conn != (Connection *)NULL) {
|
||||||
_nspr_conn->set_no_delay(true);
|
_net_conn->set_no_delay(true);
|
||||||
_qcr.add_connection(_nspr_conn);
|
_qcr.add_connection(_net_conn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef WANT_NATIVE_NET
|
#ifdef WANT_NATIVE_NET
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CConnectionRepository::connect_native
|
// Function: CConnectionRepository::connect_native
|
||||||
// Access: Published
|
// Access: Published
|
||||||
// Description: Connects to the server using a native system roger
|
// Description: Connects to the server using Panda's low-level and
|
||||||
// put together
|
// fast "native net" library.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool CConnectionRepository::
|
bool CConnectionRepository::
|
||||||
connect_native(const URLSpec &url) {
|
connect_native(const URLSpec &url) {
|
||||||
@ -178,13 +178,16 @@ connect_native(const URLSpec &url) {
|
|||||||
// is non-blocking. If you call this on a blocking
|
// is non-blocking. If you call this on a blocking
|
||||||
// socket, it will force all datagrams to be held up
|
// socket, it will force all datagrams to be held up
|
||||||
// until the socket closes.
|
// until the socket closes.
|
||||||
|
//
|
||||||
|
// This has no effect if the connection method is via
|
||||||
|
// the "native net" library.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CConnectionRepository::
|
void CConnectionRepository::
|
||||||
start_delay(double min_delay, double max_delay) {
|
start_delay(double min_delay, double max_delay) {
|
||||||
if (min_delay != 0.0 || max_delay != 0.0) {
|
if (min_delay != 0.0 || max_delay != 0.0) {
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
_qcr.start_delay(min_delay, max_delay);
|
_qcr.start_delay(min_delay, max_delay);
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
if (_http_conn != (SocketStream *)NULL) {
|
if (_http_conn != (SocketStream *)NULL) {
|
||||||
_http_conn->start_delay(min_delay, max_delay);
|
_http_conn->start_delay(min_delay, max_delay);
|
||||||
@ -206,9 +209,9 @@ start_delay(double min_delay, double max_delay) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CConnectionRepository::
|
void CConnectionRepository::
|
||||||
stop_delay() {
|
stop_delay() {
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
_qcr.stop_delay();
|
_qcr.stop_delay();
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
if (_http_conn != (SocketStream *)NULL) {
|
if (_http_conn != (SocketStream *)NULL) {
|
||||||
_http_conn->stop_delay();
|
_http_conn->stop_delay();
|
||||||
@ -312,22 +315,22 @@ is_connected() {
|
|||||||
return (_bdc.IsConnected());
|
return (_bdc.IsConnected());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
if (_nspr_conn) {
|
if (_net_conn) {
|
||||||
if (_qcm.reset_connection_available()) {
|
if (_qcm.reset_connection_available()) {
|
||||||
PT(Connection) reset_connection;
|
PT(Connection) reset_connection;
|
||||||
if (_qcm.get_reset_connection(reset_connection)) {
|
if (_qcm.get_reset_connection(reset_connection)) {
|
||||||
_qcm.close_connection(reset_connection);
|
_qcm.close_connection(reset_connection);
|
||||||
if (reset_connection == _nspr_conn) {
|
if (reset_connection == _net_conn) {
|
||||||
// Whoops, lost our connection.
|
// Whoops, lost our connection.
|
||||||
_nspr_conn = NULL;
|
_net_conn = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
if (_http_conn) {
|
if (_http_conn) {
|
||||||
@ -369,12 +372,12 @@ send_datagram(const Datagram &dg) {
|
|||||||
return _bdc.SendMessage(dg);
|
return _bdc.SendMessage(dg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
if (_nspr_conn) {
|
if (_net_conn) {
|
||||||
_cw.send(dg, _nspr_conn);
|
_cw.send(dg, _net_conn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
if (_http_conn) {
|
if (_http_conn) {
|
||||||
@ -411,11 +414,11 @@ consider_flush() {
|
|||||||
return true; //Maybe we should just flush here for now?
|
return true; //Maybe we should just flush here for now?
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
if (_nspr_conn) {
|
if (_net_conn) {
|
||||||
return _nspr_conn->consider_flush();
|
return _net_conn->consider_flush();
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
if (_http_conn) {
|
if (_http_conn) {
|
||||||
@ -443,11 +446,11 @@ flush() {
|
|||||||
return _bdc.Flush();
|
return _bdc.Flush();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
if (_nspr_conn) {
|
if (_net_conn) {
|
||||||
return _nspr_conn->flush();
|
return _net_conn->flush();
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
if (_http_conn) {
|
if (_http_conn) {
|
||||||
@ -471,12 +474,12 @@ disconnect() {
|
|||||||
_bdc.ClearAddresses();
|
_bdc.ClearAddresses();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
if (_nspr_conn) {
|
if (_net_conn) {
|
||||||
_qcm.close_connection(_nspr_conn);
|
_qcm.close_connection(_net_conn);
|
||||||
_nspr_conn = NULL;
|
_net_conn = NULL;
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
if (_http_conn) {
|
if (_http_conn) {
|
||||||
@ -502,16 +505,16 @@ do_check_datagram() {
|
|||||||
return _bdc.GetMessage(_dg);
|
return _bdc.GetMessage(_dg);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
if (_nspr_conn) {
|
if (_net_conn) {
|
||||||
_nspr_conn->consider_flush();
|
_net_conn->consider_flush();
|
||||||
if (_qcr.get_overflow_flag()) {
|
if (_qcr.get_overflow_flag()) {
|
||||||
throw_event(get_overflow_event_name());
|
throw_event(get_overflow_event_name());
|
||||||
_qcr.reset_overflow_flag();
|
_qcr.reset_overflow_flag();
|
||||||
}
|
}
|
||||||
return (_qcr.data_available() && _qcr.get_data(_dg));
|
return (_qcr.data_available() && _qcr.get_data(_dg));
|
||||||
}
|
}
|
||||||
#endif // HAVE_NSPR
|
#endif // HAVE_NET
|
||||||
|
|
||||||
#ifdef HAVE_OPENSSL
|
#ifdef HAVE_OPENSSL
|
||||||
if (_http_conn) {
|
if (_http_conn) {
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
#include "pStatCollector.h"
|
#include "pStatCollector.h"
|
||||||
#include "datagramIterator.h"
|
#include "datagramIterator.h"
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
#include "queuedConnectionManager.h"
|
#include "queuedConnectionManager.h"
|
||||||
#include "connectionWriter.h"
|
#include "connectionWriter.h"
|
||||||
#include "queuedConnectionReader.h"
|
#include "queuedConnectionReader.h"
|
||||||
@ -79,8 +79,8 @@ PUBLISHED:
|
|||||||
void set_connection_http(HTTPChannel *channel);
|
void set_connection_http(HTTPChannel *channel);
|
||||||
SocketStream *get_stream();
|
SocketStream *get_stream();
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
bool try_connect_nspr(const URLSpec &url);
|
bool try_connect_net(const URLSpec &url);
|
||||||
|
|
||||||
INLINE QueuedConnectionManager &get_qcm();
|
INLINE QueuedConnectionManager &get_qcm();
|
||||||
INLINE ConnectionWriter &get_cw();
|
INLINE ConnectionWriter &get_cw();
|
||||||
@ -140,11 +140,11 @@ private:
|
|||||||
SocketStream *_http_conn;
|
SocketStream *_http_conn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_NSPR
|
#ifdef HAVE_NET
|
||||||
QueuedConnectionManager _qcm;
|
QueuedConnectionManager _qcm;
|
||||||
ConnectionWriter _cw;
|
ConnectionWriter _cw;
|
||||||
QueuedConnectionReader _qcr;
|
QueuedConnectionReader _qcr;
|
||||||
PT(Connection) _nspr_conn;
|
PT(Connection) _net_conn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WANT_NATIVE_NET
|
#ifdef WANT_NATIVE_NET
|
||||||
|
Loading…
x
Reference in New Issue
Block a user