multicast test added
This commit is contained in:
@@ -188,6 +188,9 @@ void ServerSearchHandler::handleResponse(osiSockAddr* responseFrom,
|
||||
transport, version, command, payloadSize, payloadBuffer);
|
||||
|
||||
transport->ensureData(4+1+3+16+2);
|
||||
|
||||
size_t startPosition = payloadBuffer->getPosition();
|
||||
|
||||
const int32 searchSequenceId = payloadBuffer->getInt();
|
||||
const int8 qosCode = payloadBuffer->getByte();
|
||||
|
||||
@@ -200,9 +203,9 @@ void ServerSearchHandler::handleResponse(osiSockAddr* responseFrom,
|
||||
|
||||
// 128-bit IPv6 address
|
||||
/*
|
||||
int8* byteAddress = new int8[16];
|
||||
int8 byteAddress[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
byteAddress[i] = payloadBuffer->getByte(); };
|
||||
byteAddress[i] = payloadBuffer->getByte();
|
||||
*/
|
||||
|
||||
// IPv4 compatible IPv6 address expected
|
||||
@@ -234,7 +237,27 @@ byteAddress[i] = payloadBuffer->getByte(); };
|
||||
|
||||
const bool responseRequired = (QOS_REPLY_REQUIRED & qosCode) != 0;
|
||||
|
||||
// TODO locally broadcast if qosCode & 0x80 == 0x80
|
||||
//
|
||||
// locally broadcast if unicast (qosCode & 0x80 == 0x80)
|
||||
//
|
||||
if ((qosCode & 0x80) == 0x80)
|
||||
{
|
||||
BlockingUDPTransport::shared_pointer bt = _context->getLocalMulticastTransport();
|
||||
if (bt)
|
||||
{
|
||||
// clear unicast flag
|
||||
payloadBuffer->put(startPosition+4, (int8)(qosCode & ~0x80));
|
||||
|
||||
// update response address
|
||||
payloadBuffer->setPosition(startPosition+8);
|
||||
encodeAsIPv6Address(payloadBuffer, &responseAddress);
|
||||
|
||||
payloadBuffer->setPosition(payloadBuffer->getLimit()); // send will call flip()
|
||||
|
||||
bt->send(payloadBuffer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
|
||||
@@ -295,6 +295,42 @@ void ServerContextImpl::initializeBroadcastTransport()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
/*
|
||||
// TODO configurable local NIF, address
|
||||
// setup local broadcasting
|
||||
NetworkInterface localNIF = InetAddressUtil.getLoopbackNIF();
|
||||
if (localNIF != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
InetAddress group = InetAddress.getByName("224.0.0.128");
|
||||
broadcastTransport.join(group, localNIF);
|
||||
|
||||
logger.config("Local multicast enabled on " + group + ":" + broadcastPort + " using " + localNIF.getDisplayName() + ".");
|
||||
|
||||
localMulticastTransport = (BlockingUDPTransport)broadcastConnector.connect(
|
||||
// localMulticastTransport = (UDPTransport)broadcastConnector.connect(
|
||||
null, serverResponseHandler,
|
||||
listenLocalAddress, PVAConstants.PVA_PROTOCOL_REVISION,
|
||||
PVAConstants.PVA_DEFAULT_PRIORITY);
|
||||
localMulticastTransport.setMutlicastNIF(localNIF, true);
|
||||
localMulticastTransport.setSendAddresses(new InetSocketAddress[] {
|
||||
new InetSocketAddress(group, broadcastPort)
|
||||
});
|
||||
}
|
||||
catch (Throwable th)
|
||||
{
|
||||
logger.log(Level.CONFIG, "Failed to join to a multicast group, local multicast disabled.", th);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.config("Failed to detect a loopback network interface, local multicast disabled.");
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
_broadcastTransport->start();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
@@ -398,6 +434,12 @@ void ServerContextImpl::internalDestroy()
|
||||
_broadcastTransport->close();
|
||||
_broadcastTransport.reset();
|
||||
}
|
||||
// and close local multicast transport
|
||||
if (_localMulticastTransport.get())
|
||||
{
|
||||
_localMulticastTransport->close();
|
||||
_localMulticastTransport.reset();
|
||||
}
|
||||
|
||||
// stop accepting connections
|
||||
if (_acceptor.get())
|
||||
@@ -568,6 +610,11 @@ BlockingUDPTransport::shared_pointer ServerContextImpl::getBroadcastTransport()
|
||||
return _broadcastTransport;
|
||||
}
|
||||
|
||||
BlockingUDPTransport::shared_pointer ServerContextImpl::getLocalMulticastTransport()
|
||||
{
|
||||
return _localMulticastTransport;
|
||||
}
|
||||
|
||||
ChannelProviderRegistry::shared_pointer ServerContextImpl::getChannelProviderRegistry()
|
||||
{
|
||||
return _channelProviderRegistry;
|
||||
|
||||
@@ -142,6 +142,9 @@ public:
|
||||
std::auto_ptr<ResponseHandler> createResponseHandler();
|
||||
virtual void newServerDetected();
|
||||
|
||||
|
||||
BlockingUDPTransport::shared_pointer getLocalMulticastTransport();
|
||||
|
||||
/**
|
||||
* Version.
|
||||
*/
|
||||
@@ -349,7 +352,12 @@ private:
|
||||
*/
|
||||
BlockingUDPTransport::shared_pointer _broadcastTransport;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Local broadcast transport needed for local fan-out.
|
||||
*/
|
||||
BlockingUDPTransport::shared_pointer _localMulticastTransport;
|
||||
|
||||
/**
|
||||
* Beacon emitter.
|
||||
*/
|
||||
BeaconEmitter::shared_pointer _beaconEmitter;
|
||||
|
||||
Reference in New Issue
Block a user