Skip to content
Snippets Groups Projects
Commit c9f1f947 authored by bontric's avatar bontric
Browse files

Update MailboxOwnerSession

parent cb4f20b6
No related branches found
No related tags found
No related merge requests found
......@@ -7,16 +7,25 @@ import org.briarproject.bramble.api.transport.StreamReaderFactory;
import org.briarproject.bramble.api.transport.StreamWriterFactory;
import org.briarproject.bramble.mailbox.protocol.MailboxMessage;
import org.briarproject.bramble.mailbox.protocol.MailboxProtocol;
import org.briarproject.bramble.mailbox.protocol.MailboxRequest;
import org.briarproject.bramble.mailbox.protocol.MailboxRequestHandler;
import org.briarproject.bramble.mailbox.protocol.MailboxRequestStore;
import java.net.ProtocolException;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
import static org.briarproject.bramble.mailbox.protocol.MailboxMessage.TYPE.STORE;
class MailboxOwnerSession extends AbstractMailboxSession {
/**
* This session represents a connection from the mailbox owner to their own mailbox
*/
public class MailboxOwnerSession extends AbstractMailboxSession {
private static final Logger LOG =
Logger.getLogger(MailboxOwnerSession.class.getName());
private final MailboxStorage mailboxStorage;
public MailboxOwnerSession(ContactId contactId, Executor ioExecutor,
KeyManager keyManager,
......@@ -24,25 +33,53 @@ class MailboxOwnerSession extends AbstractMailboxSession {
StreamWriterFactory streamWriterFactory,
StreamReaderFactory streamReaderFactory,
MailboxProtocol mailboxProtocol, int transportMaxLatency,
int transportMaxIdleTime) {
int transportMaxIdleTime, MailboxStorage mailboxStorage) {
super(ioExecutor, keyManager, syncSessionFactory, streamWriterFactory,
streamReaderFactory, mailboxProtocol, transportMaxLatency,
transportMaxIdleTime, contactId);
this.mailboxStorage = mailboxStorage;
enableSYNCHandling();
mailboxProtocol.registerRequestHandler(new STOREHandler());
mailboxProtocol.enableRequestHandling();
registerSupportedRequest(MailboxMessage.TYPE.SYNC);
registerSupportedRequest(MailboxMessage.TYPE.TAKE);
}
@Override
public void run() {
try {
waitForHandlersToFinish();
awaitSYNCHandlerFinished();
} catch (InterruptedException e) {
if (LOG.isLoggable(INFO))
LOG.info(e.toString());
}
}
private class STOREHandler implements MailboxRequestHandler {
@Override
public void handleRequest(MailboxRequest request)
throws ProtocolException {
MailboxRequestStore storeReq = (MailboxRequestStore) request;
if (!storeReq.hasContactId())
throw new ProtocolException(
"Contact Id must be set for owner to mailbox STORE requests");
mailboxStorage
.storeStream(storeReq.getContactId(),
storeReq.getEncryptedSyncStream());
}
@Override
public MailboxMessage.TYPE getType() {
return STORE;
}
@Override
public void protocolFinished() {
mailboxStorage.close();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment