Skip to content

Commit

Permalink
FS|RemoteFeed: Send only relevant metadata about files
Browse files Browse the repository at this point in the history
A file object's namespace contains a bunch of functions etc. that
are not relevant for sharing over the network.
  • Loading branch information
skyjake committed Oct 6, 2017
1 parent 1710e6a commit 943dec5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
8 changes: 8 additions & 0 deletions doomsday/apps/server/src/remotefeeduser.cpp
Expand Up @@ -32,6 +32,7 @@ DENG2_PIMPL(RemoteFeedUser)

Impl(Public *i, Socket *s) : Base(i), socket(s)
{
LOG_NET_MSG("Setting up RemoteFeedUser %p") << thisPublic;
QObject::connect(s, &Socket::messagesReady, [this] () { receiveMessages(); });
QObject::connect(s, &Socket::disconnected, [this] ()
{
Expand All @@ -40,6 +41,9 @@ DENG2_PIMPL(RemoteFeedUser)
i->userDisconnected(self());
}
});

// We took over an open socket, there may already be messages waiting.
receiveMessages();
}

void receiveMessages()
Expand All @@ -52,6 +56,8 @@ DENG2_PIMPL(RemoteFeedUser)
std::unique_ptr<Message> message(socket->receive());
std::unique_ptr<Packet> packet(protocol.interpret(*message));

LOG_NET_MSG("received packet '%s'") << packet->type();

if (protocol.recognize(*packet) == RemoteFeedProtocol::Query)
{
handleQuery(packet->as<RemoteFeedQueryPacket>());
Expand Down Expand Up @@ -84,13 +90,15 @@ DENG2_PIMPL(RemoteFeedUser)
{
LOG_NET_WARNING("%s not found!") << query.path();
}
LOG_NET_MSG("%s") << response->metadata().asText();
break;

case RemoteFeedQueryPacket::FileContents:

break;
}

LOG_NET_MSG("Sending response %i") << query.id();
socket->sendPacket(*response);
}
};
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/server/src/remoteuser.cpp
Expand Up @@ -252,6 +252,8 @@ String RemoteUser::name() const
Socket *RemoteUser::takeSocket()
{
Socket *sock = d->socket;
QObject::disconnect(sock, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
QObject::disconnect(sock, SIGNAL(messagesReady()), this, SLOT(handleIncomingPackets()));
d->socket = 0;
d->state = Disconnected; // not signaled
return sock;
Expand Down
22 changes: 20 additions & 2 deletions doomsday/sdk/libcore/src/filesys/remotefeedprotocol.cpp
Expand Up @@ -19,6 +19,7 @@
#include "de/RemoteFeedProtocol"
#include "de/TextValue"
#include "de/RecordValue"
#include "de/Folder"

namespace de {

Expand Down Expand Up @@ -78,9 +79,26 @@ RemoteFeedMetadataPacket::RemoteFeedMetadataPacket()

void RemoteFeedMetadataPacket::addFile(File const &file)
{
std::unique_ptr<Record> fileMeta(new Record(file.objectNamespace()));
auto const &ns = file.objectNamespace();
auto const status = file.status();

// TODO: Omit irrelevant/local information?
std::unique_ptr<Record> fileMeta(new Record);

fileMeta->addTime ("modifiedAt", status.modifiedAt);
fileMeta->addNumber("type", status.type());
if (status.type() == File::Status::FOLDER)
{
fileMeta->addNumber("size", file.as<Folder>().contents().size());
}
else
{
fileMeta->addNumber("size", status.size);
}
if (ns.hasSubrecord("package"))
{
fileMeta->add("package", new Record(ns["package"].valueAsRecord(),
Record::IgnoreDoubleUnderscoreMembers));
}

_metadata.add(new TextValue(file.name()),
new RecordValue(fileMeta.release(), RecordValue::OwnsRecord));
Expand Down
5 changes: 4 additions & 1 deletion doomsday/sdk/libcore/src/filesys/remotefeedrelay.cpp
Expand Up @@ -86,7 +86,7 @@ DENG2_PIMPL(RemoteFeedRelay)

virtual void handleError(QString errorMessage)
{
LOG_NET_ERROR("Error accessing remote file repository \"%s\" (%s) " DENG2_CHAR_MDASH
LOG_NET_ERROR("Error accessing remote file repository \"%s\": %s " DENG2_CHAR_MDASH
"files from repository may not be available")
<< address
<< errorMessage;
Expand All @@ -105,6 +105,7 @@ DENG2_PIMPL(RemoteFeedRelay)
}
else
{
qDebug() << "[RemoteFeedRelay] Query" << query.id << "is deferred";
deferredQueries.append(query);
}
}
Expand Down Expand Up @@ -187,6 +188,8 @@ DENG2_PIMPL(RemoteFeedRelay)
{
DENG2_ASSERT(query.isValid());

qDebug() << "transmitting query" << query.id << query.path;

RemoteFeedQueryPacket packet;
packet.setId(query.id);
packet.setPath(query.path);
Expand Down

0 comments on commit 943dec5

Please sign in to comment.