Add a method for checking whether we can send streams.

This commit is contained in:
akwizgran
2018-03-28 12:08:08 +01:00
parent 798b871cc9
commit f7c2f86499
5 changed files with 53 additions and 15 deletions

View File

@@ -160,6 +160,12 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
}
}
@Override
public boolean canSendOutgoingStreams(ContactId c, TransportId t) {
TransportKeyManager m = managers.get(t);
return m == null ? false : m.canSendOutgoingStreams(c);
}
@Override
public StreamContext getStreamContext(ContactId c, TransportId t)
throws DbException {

View File

@@ -29,6 +29,8 @@ interface TransportKeyManager {
void removeContact(ContactId c);
boolean canSendOutgoingStreams(ContactId c);
@Nullable
StreamContext getStreamContext(Transaction txn, ContactId c)
throws DbException;

View File

@@ -278,6 +278,21 @@ class TransportKeyManagerImpl implements TransportKeyManager {
}
}
@Override
public boolean canSendOutgoingStreams(ContactId c) {
lock.lock();
try {
MutableKeySet ks = outContexts.get(c);
if (ks == null) return false;
MutableOutgoingKeys outKeys =
ks.getTransportKeys().getCurrentOutgoingKeys();
if (!outKeys.isActive()) throw new AssertionError();
return outKeys.getStreamCounter() <= MAX_32_BIT_UNSIGNED;
} finally {
lock.unlock();
}
}
@Override
public StreamContext getStreamContext(Transaction txn, ContactId c)
throws DbException {