blob: 7ce7f123921ecfe3ea2396be2c83cdb156242fc5 (
plain) (
tree)
|
|
/*
# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# src/net/pvsServiceBroadcast.cpp
# - broadcast sessionname
# -----------------------------------------------------------------------------
*/
/********** COMPILE-TIME SETTINGS ***************/
#include "pvsServiceBroadcast.h"
#include "src/setup.h"
#include <cassert>
#include "src/util/serviceDiscoveryUtil.h"
#include <QNetworkInterface>
#include <QNetworkAddressEntry>
PVSServiceBroadcast::PVSServiceBroadcast()
{
_announce = NULL;
_timer = 0;
_broadcaster.bind(SD_PORT_CONSOLE);
}
PVSServiceBroadcast::~PVSServiceBroadcast()
{
if (_announce != NULL) delete _announce;
if (_timer != 0) this->killTimer(_timer);
}
void PVSServiceBroadcast::setFingerprint(QByteArray sha1)
{
if (_announce != NULL) _announce->clear();
else _announce = new QByteArray();
appendSdField(_announce, "hsh", QString(sha1.toBase64()));
appendSdField(_announce, "prt", SERVER_PORT); // TODO: maybe this has to come from somewhere else if configurable
appendSdField(_announce, "aut", "SHA1");
if (_timer == 0) _timer = this->startTimer(SB_INTERVAL * 1000);
}
void PVSServiceBroadcast::timerEvent(QTimerEvent *event)
{
foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces())
foreach (QNetworkAddressEntry entry, interface.addressEntries())
if (!entry.broadcast().isNull() && entry.broadcast().toString() != "127.255.255.255")
_everyone.append(entry.broadcast());
if (_everyone.isEmpty())
qDebug("ERROR: No broadcast address found");
if (_announce == NULL) return;
foreach (QHostAddress bcast, _everyone)
{
qDebug("DEBUG: Broadcasting to %s:%i", qPrintable(bcast.toString()),SD_PORT_CLIENT);
_broadcaster.writeDatagram(*_announce, bcast, SD_PORT_CLIENT);
}
_everyone.clear();
}
|