aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/main/java/org/whispersystems/libaxolotl/state/SessionStore.java
blob: c5ad00b0b31020c17ed44e587f88fa409ae9a09e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.whispersystems.libaxolotl.state;

import java.util.List;

/**
 * The interface to the durable store of session state information
 * for remote clients.
 *
 * @author Moxie Marlinspike
 */
public interface SessionStore {

  /**
   * Returns a copy of the {@link SessionRecord} corresponding to the recipientId + deviceId tuple,
   * or a new SessionRecord if one does not currently exist.
   * <p>
   * It is important that implementations return a copy of the current durable information.  The
   * returned SessionRecord may be modified, but those changes should not have an effect on the
   * durable session state (what is returned by subsequent calls to this method) without the
   * store method being called here first.
   *
   * @param recipientId The recipientID of the remote client.
   * @param deviceId The deviceID of the remote client.
   * @return a copy of the SessionRecord corresponding to the recipientId + deviceId tuple, or
   *         a new SessionRecord if one does not currently exist.
   */
  public SessionRecord loadSession(long recipientId, int deviceId);

  /**
   * Returns all known devices with active sessions for a recipient
   *
   * @param recipientId the recipient ID.
   * @return all known sub-devices with active sessions.
   */
  public List<Integer> getSubDeviceSessions(long recipientId);

  /**
   * Commit to storage the {@link SessionRecord} for a given recipientId + deviceId tuple.
   * @param recipientId the recipient ID of the remote client.
   * @param deviceId the device ID of the remote client.
   * @param record the current SessionRecord for the remote client.
   */
  public void storeSession(long recipientId, int deviceId, SessionRecord record);

  /**
   * Determine whether there is a committed {@link SessionRecord} for a recipientId + deviceId tuple.
   * @param recipientId the recipient ID of the remote client.
   * @param deviceId the device ID of the remote client.
   * @return true if a {@link SessionRecord} exists, false otherwise.
   */
  public boolean containsSession(long recipientId, int deviceId);

  /**
   * Remove a {@link SessionRecord} for a recipientId + deviceId tuple.
   *
   * @param recipientId the recipient ID of the remote client.
   * @param deviceId the device ID of the remote client.
   */
  public void deleteSession(long recipientId, int deviceId);

  /**
   * Remove the {@link SessionRecord}s corresponding to all devices of a recipientId.
   *
   * @param recipientId the recipient ID of the remote client.
   */
  public void deleteAllSessions(long recipientId);

}