Merge branch '174-bsp-renaming-again'

Conflicts:
	briar-android/src/org/briarproject/android/contact/ConversationActivity.java
This commit is contained in:
akwizgran
2015-12-16 10:40:17 +00:00
98 changed files with 900 additions and 799 deletions

View File

@@ -23,7 +23,7 @@ import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.SettingsUpdatedEvent; import org.briarproject.api.event.SettingsUpdatedEvent;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.util.HashMap; import java.util.HashMap;

View File

@@ -23,7 +23,7 @@ import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent; import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.lifecycle.LifecycleManager; import org.briarproject.api.lifecycle.LifecycleManager;
import org.briarproject.api.lifecycle.LifecycleManager.StartResult; import org.briarproject.api.lifecycle.LifecycleManager.StartResult;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;

View File

@@ -1,47 +1,5 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.Menu.NONE;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
import java.util.Collection;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.invitation.AddContactActivity;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.AuthorId;
import org.briarproject.api.Contact;
import org.briarproject.api.ContactId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.event.ContactAddedEvent;
import org.briarproject.api.event.ContactConnectedEvent;
import org.briarproject.api.event.ContactDisconnectedEvent;
import org.briarproject.api.event.ContactRemovedEvent;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.MessageExpiredEvent;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.plugins.ConnectionRegistry;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
@@ -60,6 +18,48 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.invitation.AddContactActivity;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.AuthorId;
import org.briarproject.api.Contact;
import org.briarproject.api.ContactId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.event.ContactAddedEvent;
import org.briarproject.api.event.ContactConnectedEvent;
import org.briarproject.api.event.ContactDisconnectedEvent;
import org.briarproject.api.event.ContactRemovedEvent;
import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.MessageExpiredEvent;
import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageHeader;
import java.util.Collection;
import java.util.logging.Logger;
import javax.inject.Inject;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.Menu.NONE;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
public class ContactListActivity extends BriarActivity public class ContactListActivity extends BriarActivity
implements OnClickListener, OnItemClickListener, OnCreateContextMenuListener, implements OnClickListener, OnItemClickListener, OnCreateContextMenuListener,
EventListener { EventListener {

View File

@@ -1,10 +1,10 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import java.util.Collection;
import org.briarproject.api.Contact; import org.briarproject.api.Contact;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.MessageHeader;
import java.util.Collection;
// This class is not thread-safe // This class is not thread-safe
class ContactListItem { class ContactListItem {

View File

@@ -26,8 +26,6 @@ import org.briarproject.api.android.AndroidNotificationManager;
import org.briarproject.api.crypto.CryptoExecutor; import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.db.MessageHeader.State;
import org.briarproject.api.db.NoSuchContactException; import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchSubscriptionException;
@@ -41,12 +39,14 @@ import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.MessageExpiredEvent; import org.briarproject.api.event.MessageExpiredEvent;
import org.briarproject.api.event.MessagesAckedEvent; import org.briarproject.api.event.MessagesAckedEvent;
import org.briarproject.api.event.MessagesSentEvent; import org.briarproject.api.event.MessagesSentEvent;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.Message;
import org.briarproject.api.messaging.MessageFactory;
import org.briarproject.api.messaging.MessageId;
import org.briarproject.api.plugins.ConnectionRegistry; import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.sync.MessageHeader.State;
import org.briarproject.api.sync.MessageId;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.io.IOException; import java.io.IOException;

View File

@@ -1,21 +1,5 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import static android.view.Gravity.BOTTOM;
import static android.view.Gravity.LEFT;
import static android.view.View.INVISIBLE;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import java.util.ArrayList;
import org.briarproject.R;
import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.db.MessageHeader.State;
import org.briarproject.util.StringUtils;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.text.format.DateUtils; import android.text.format.DateUtils;
@@ -27,6 +11,21 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.sync.MessageHeader.State;
import org.briarproject.util.StringUtils;
import java.util.ArrayList;
import static android.view.Gravity.BOTTOM;
import static android.view.Gravity.LEFT;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
class ConversationAdapter extends ArrayAdapter<ConversationItem> { class ConversationAdapter extends ArrayAdapter<ConversationItem> {
private final int pad; private final int pad;

View File

@@ -1,7 +1,7 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.db.MessageHeader.State; import org.briarproject.api.sync.MessageHeader.State;
// This class is not thread-safe // This class is not thread-safe
class ConversationItem { class ConversationItem {

View File

@@ -1,34 +1,5 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
import static org.briarproject.api.Author.Status.VERIFIED;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.AuthorView;
import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.AuthorId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.MessageId;
import org.briarproject.util.StringUtils;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
@@ -40,6 +11,35 @@ import android.widget.LinearLayout;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.AuthorView;
import org.briarproject.android.util.ElasticHorizontalSpace;
import org.briarproject.android.util.HorizontalBorder;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.AuthorId;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageId;
import org.briarproject.util.StringUtils;
import java.util.logging.Logger;
import javax.inject.Inject;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_VERTICAL;
import static android.widget.LinearLayout.HORIZONTAL;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP_1;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP_1;
import static org.briarproject.api.Author.Status.VERIFIED;
public class ReadPrivateMessageActivity extends BriarActivity public class ReadPrivateMessageActivity extends BriarActivity
implements OnClickListener { implements OnClickListener {

View File

@@ -1,5 +1,42 @@
package org.briarproject.android.contact; package org.briarproject.android.contact;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.CommonLayoutParams;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.AuthorId;
import org.briarproject.api.LocalAuthor;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.Message;
import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.sync.MessageId;
import org.briarproject.util.StringUtils;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject;
import static android.text.InputType.TYPE_CLASS_TEXT; import static android.text.InputType.TYPE_CLASS_TEXT;
import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; import static android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
import static android.text.TextUtils.TruncateAt.END; import static android.text.TextUtils.TruncateAt.END;
@@ -13,43 +50,6 @@ import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP; import static org.briarproject.android.util.CommonLayoutParams.MATCH_WRAP;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.R;
import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.CommonLayoutParams;
import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.AuthorId;
import org.briarproject.api.LocalAuthor;
import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.Message;
import org.briarproject.api.messaging.MessageFactory;
import org.briarproject.api.messaging.MessageId;
import org.briarproject.util.StringUtils;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class WritePrivateMessageActivity extends BriarActivity public class WritePrivateMessageActivity extends BriarActivity
implements OnClickListener { implements OnClickListener {

View File

@@ -21,8 +21,8 @@ import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent; import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
import org.briarproject.api.event.SubscriptionAddedEvent; import org.briarproject.api.event.SubscriptionAddedEvent;
import org.briarproject.api.event.SubscriptionRemovedEvent; import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@@ -1,7 +1,7 @@
package org.briarproject.android.forum; package org.briarproject.android.forum;
import org.briarproject.api.Contact; import org.briarproject.api.Contact;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import java.util.Collection; import java.util.Collection;

View File

@@ -18,8 +18,8 @@ import org.briarproject.android.BriarActivity;
import org.briarproject.android.util.LayoutUtils; import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupFactory; import org.briarproject.api.sync.GroupFactory;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -38,7 +38,7 @@ import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH; import static org.briarproject.android.util.CommonLayoutParams.MATCH_MATCH;
import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP; import static org.briarproject.android.util.CommonLayoutParams.WRAP_WRAP;
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH; import static org.briarproject.api.sync.MessagingConstants.MAX_GROUP_NAME_LENGTH;
public class CreateForumActivity extends BriarActivity public class CreateForumActivity extends BriarActivity
implements OnEditorActionListener, OnClickListener { implements OnEditorActionListener, OnClickListener {

View File

@@ -21,7 +21,6 @@ import org.briarproject.api.Author;
import org.briarproject.api.android.AndroidNotificationManager; import org.briarproject.api.android.AndroidNotificationManager;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.event.Event; import org.briarproject.api.event.Event;
@@ -30,9 +29,10 @@ import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent; import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.event.MessageExpiredEvent; import org.briarproject.api.event.MessageExpiredEvent;
import org.briarproject.api.event.SubscriptionRemovedEvent; import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.sync.MessageId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@@ -14,7 +14,7 @@ import org.briarproject.R;
import org.briarproject.android.util.AuthorView; import org.briarproject.android.util.AuthorView;
import org.briarproject.android.util.LayoutUtils; import org.briarproject.android.util.LayoutUtils;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.sync.MessageHeader;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;

View File

@@ -1,7 +1,7 @@
package org.briarproject.android.forum; package org.briarproject.android.forum;
import org.briarproject.api.Contact; import org.briarproject.api.Contact;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import java.util.Collection; import java.util.Collection;

View File

@@ -1,6 +1,6 @@
package org.briarproject.android.forum; package org.briarproject.android.forum;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.sync.MessageHeader;
// This class is not thread-safe // This class is not thread-safe
class ForumItem { class ForumItem {

View File

@@ -25,7 +25,6 @@ import org.briarproject.android.util.LayoutUtils;
import org.briarproject.android.util.ListLoadingProgressBar; import org.briarproject.android.util.ListLoadingProgressBar;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.db.NoSuchSubscriptionException; import org.briarproject.api.db.NoSuchSubscriptionException;
import org.briarproject.api.event.Event; import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventBus;
@@ -35,8 +34,9 @@ import org.briarproject.api.event.MessageExpiredEvent;
import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent; import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
import org.briarproject.api.event.SubscriptionAddedEvent; import org.briarproject.api.event.SubscriptionAddedEvent;
import org.briarproject.api.event.SubscriptionRemovedEvent; import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.MessageHeader;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;

View File

@@ -1,7 +1,7 @@
package org.briarproject.android.forum; package org.briarproject.android.forum;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.MessageHeader;
import java.util.Collection; import java.util.Collection;

View File

@@ -21,8 +21,8 @@ import org.briarproject.api.Author;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.util.logging.Logger; import java.util.logging.Logger;

View File

@@ -19,7 +19,7 @@ import org.briarproject.api.Contact;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;

View File

@@ -31,11 +31,11 @@ import org.briarproject.api.crypto.KeyParser;
import org.briarproject.api.crypto.PrivateKey; import org.briarproject.api.crypto.PrivateKey;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageFactory; import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.io.IOException; import java.io.IOException;

View File

@@ -2,7 +2,7 @@ package org.briarproject.api.android;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.lifecycle.Service; import org.briarproject.api.lifecycle.Service;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
/** /**
* Manages notifications for private messages and group posts. All methods must * Manages notifications for private messages and group posts. All methods must

View File

@@ -9,19 +9,19 @@ import org.briarproject.api.Settings;
import org.briarproject.api.TransportConfig; import org.briarproject.api.TransportConfig;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
import org.briarproject.api.TransportProperties; import org.briarproject.api.TransportProperties;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.Offer; import org.briarproject.api.sync.Offer;
import org.briarproject.api.messaging.Request; import org.briarproject.api.sync.Request;
import org.briarproject.api.messaging.RetentionAck; import org.briarproject.api.sync.RetentionAck;
import org.briarproject.api.messaging.RetentionUpdate; import org.briarproject.api.sync.RetentionUpdate;
import org.briarproject.api.messaging.SubscriptionAck; import org.briarproject.api.sync.SubscriptionAck;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.transport.TransportKeys; import org.briarproject.api.transport.TransportKeys;
import java.io.IOException; import java.io.IOException;
@@ -179,7 +179,7 @@ public interface DatabaseComponent {
* Returns the headers of all messages in the inbox group for the given * Returns the headers of all messages in the inbox group for the given
* contact, or null if no inbox group has been set. * contact, or null if no inbox group has been set.
*/ */
Collection<MessageHeader> getInboxMessageHeaders(ContactId c) Collection<org.briarproject.api.sync.MessageHeader> getInboxMessageHeaders(ContactId c)
throws DbException; throws DbException;
/** Returns the local pseudonym with the given ID. */ /** Returns the local pseudonym with the given ID. */
@@ -199,7 +199,7 @@ public interface DatabaseComponent {
byte[] getMessageBody(MessageId m) throws DbException; byte[] getMessageBody(MessageId m) throws DbException;
/** Returns the headers of all messages in the given group. */ /** Returns the headers of all messages in the given group. */
Collection<MessageHeader> getMessageHeaders(GroupId g) Collection<org.briarproject.api.sync.MessageHeader> getMessageHeaders(GroupId g)
throws DbException; throws DbException;
/** Returns true if the given message is marked as read. */ /** Returns true if the given message is marked as read. */

View File

@@ -1,7 +1,7 @@
package org.briarproject.api.event; package org.briarproject.api.event;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
/** An event that is broadcast when a message is added to the database. */ /** An event that is broadcast when a message is added to the database. */
public class MessageAddedEvent extends Event { public class MessageAddedEvent extends Event {

View File

@@ -1,9 +1,9 @@
package org.briarproject.api.event; package org.briarproject.api.event;
import java.util.Collection;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import java.util.Collection;
/** An event that is broadcast when messages are acked by a contact. */ /** An event that is broadcast when messages are acked by a contact. */
public class MessagesAckedEvent extends Event { public class MessagesAckedEvent extends Event {

View File

@@ -1,9 +1,9 @@
package org.briarproject.api.event; package org.briarproject.api.event;
import java.util.Collection;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import java.util.Collection;
/** An event that is broadcast when messages are sent to a contact. */ /** An event that is broadcast when messages are sent to a contact. */
public class MessagesSentEvent extends Event { public class MessagesSentEvent extends Event {

View File

@@ -1,6 +1,6 @@
package org.briarproject.api.event; package org.briarproject.api.event;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
/** An event that is broadcast when the user subscribes to a group. */ /** An event that is broadcast when the user subscribes to a group. */
public class SubscriptionAddedEvent extends Event { public class SubscriptionAddedEvent extends Event {

View File

@@ -1,6 +1,6 @@
package org.briarproject.api.event; package org.briarproject.api.event;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
/** An event that is broadcast when the user unsubscribes from a group. */ /** An event that is broadcast when the user unsubscribes from a group. */
public class SubscriptionRemovedEvent extends Event { public class SubscriptionRemovedEvent extends Event {

View File

@@ -1,34 +0,0 @@
package org.briarproject.api.messaging;
import java.io.IOException;
public interface PacketWriter {
int getMaxMessagesForAck(long capacity);
int getMaxMessagesForRequest(long capacity);
int getMaxMessagesForOffer(long capacity);
void writeAck(Ack a) throws IOException;
void writeMessage(byte[] raw) throws IOException;
void writeOffer(Offer o) throws IOException;
void writeRequest(Request r) throws IOException;
void writeRetentionAck(RetentionAck a) throws IOException;
void writeRetentionUpdate(RetentionUpdate u) throws IOException;
void writeSubscriptionAck(SubscriptionAck a) throws IOException;
void writeSubscriptionUpdate(SubscriptionUpdate u) throws IOException;
void writeTransportAck(TransportAck a) throws IOException;
void writeTransportUpdate(TransportUpdate u) throws IOException;
void flush() throws IOException;
}

View File

@@ -1,18 +0,0 @@
package org.briarproject.api.messaging;
import java.util.Collection;
/** A packet requesting one or more {@link Message}s from the recipient. */
public class Request {
private final Collection<MessageId> requested;
public Request(Collection<MessageId> requested) {
this.requested = requested;
}
/** Returns the identifiers of the requested messages. */
public Collection<MessageId> getMessageIds() {
return requested;
}
}

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.util.Collection; import java.util.Collection;

View File

@@ -1,7 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@@ -19,9 +16,9 @@ public class Group {
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
if (length == 0 || length > MAX_GROUP_NAME_LENGTH) if (length == 0 || length > MessagingConstants.MAX_GROUP_NAME_LENGTH)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
if (salt.length != GROUP_SALT_LENGTH) if (salt.length != MessagingConstants.GROUP_SALT_LENGTH)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
this.id = id; this.id = id;
this.name = name; this.name = name;

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
public interface GroupFactory { public interface GroupFactory {

View File

@@ -1,9 +1,9 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.util.Arrays;
import org.briarproject.api.UniqueId; import org.briarproject.api.UniqueId;
import java.util.Arrays;
/** /**
* Type-safe wrapper for a byte array that uniquely identifies a {@link Group}. * Type-safe wrapper for a byte array that uniquely identifies a {@link Group}.
*/ */

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import org.briarproject.api.Author; import org.briarproject.api.Author;

View File

@@ -1,18 +1,18 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.io.IOException;
import java.security.GeneralSecurityException;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.crypto.PrivateKey; import org.briarproject.api.crypto.PrivateKey;
import java.io.IOException;
import java.security.GeneralSecurityException;
public interface MessageFactory { public interface MessageFactory {
Message createAnonymousMessage(MessageId parent, Group group, Message createAnonymousMessage(MessageId parent, org.briarproject.api.sync.Group group,
String contentType, long timestamp, byte[] body) throws IOException, String contentType, long timestamp, byte[] body) throws IOException,
GeneralSecurityException; GeneralSecurityException;
Message createPseudonymousMessage(MessageId parent, Group group, Message createPseudonymousMessage(MessageId parent, org.briarproject.api.sync.Group group,
Author author, PrivateKey privateKey, String contentType, Author author, PrivateKey privateKey, String contentType,
long timestamp, byte[] body) throws IOException, long timestamp, byte[] body) throws IOException,
GeneralSecurityException; GeneralSecurityException;

View File

@@ -1,12 +1,10 @@
package org.briarproject.api.db; package org.briarproject.api.sync;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.MessageId;
public class MessageHeader { public class MessageHeader {
public enum State { STORED, SENT, DELIVERED }; public enum State { STORED, SENT, DELIVERED }
private final MessageId id, parent; private final MessageId id, parent;
private final GroupId groupId; private final GroupId groupId;

View File

@@ -1,9 +1,9 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.util.Arrays;
import org.briarproject.api.UniqueId; import org.briarproject.api.UniqueId;
import java.util.Arrays;
/** /**
* Type-safe wrapper for a byte array that uniquely identifies a * Type-safe wrapper for a byte array that uniquely identifies a
* {@link Message}. * {@link Message}.

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
public interface MessagingConstants { public interface MessagingConstants {

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.io.IOException; import java.io.IOException;

View File

@@ -1,11 +1,11 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.io.InputStream;
import java.io.OutputStream;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
import java.io.InputStream;
import java.io.OutputStream;
public interface MessagingSessionFactory { public interface MessagingSessionFactory {
MessagingSession createIncomingSession(ContactId c, TransportId t, MessagingSession createIncomingSession(ContactId c, TransportId t,

View File

@@ -1,8 +1,8 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.util.Collection; import java.util.Collection;
/** A packet offering the recipient one or more {@link Messages}. */ /** A packet offering the recipient one or more {@link Message}s. */
public class Offer { public class Offer {
private final Collection<MessageId> offered; private final Collection<MessageId> offered;

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.io.IOException; import java.io.IOException;
@@ -19,20 +19,20 @@ public interface PacketReader {
Request readRequest() throws IOException; Request readRequest() throws IOException;
boolean hasRetentionAck() throws IOException; boolean hasRetentionAck() throws IOException;
RetentionAck readRetentionAck() throws IOException; org.briarproject.api.sync.RetentionAck readRetentionAck() throws IOException;
boolean hasRetentionUpdate() throws IOException; boolean hasRetentionUpdate() throws IOException;
RetentionUpdate readRetentionUpdate() throws IOException; org.briarproject.api.sync.RetentionUpdate readRetentionUpdate() throws IOException;
boolean hasSubscriptionAck() throws IOException; boolean hasSubscriptionAck() throws IOException;
SubscriptionAck readSubscriptionAck() throws IOException; org.briarproject.api.sync.SubscriptionAck readSubscriptionAck() throws IOException;
boolean hasSubscriptionUpdate() throws IOException; boolean hasSubscriptionUpdate() throws IOException;
SubscriptionUpdate readSubscriptionUpdate() throws IOException; org.briarproject.api.sync.SubscriptionUpdate readSubscriptionUpdate() throws IOException;
boolean hasTransportAck() throws IOException; boolean hasTransportAck() throws IOException;
TransportAck readTransportAck() throws IOException; TransportAck readTransportAck() throws IOException;
boolean hasTransportUpdate() throws IOException; boolean hasTransportUpdate() throws IOException;
TransportUpdate readTransportUpdate() throws IOException; org.briarproject.api.sync.TransportUpdate readTransportUpdate() throws IOException;
} }

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.io.InputStream; import java.io.InputStream;

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
/** Packet types for the messaging protocol. */ /** Packet types for the messaging protocol. */
public interface PacketTypes { public interface PacketTypes {

View File

@@ -0,0 +1,34 @@
package org.briarproject.api.sync;
import java.io.IOException;
public interface PacketWriter {
int getMaxMessagesForAck(long capacity);
int getMaxMessagesForRequest(long capacity);
int getMaxMessagesForOffer(long capacity);
void writeAck(Ack a) throws IOException;
void writeMessage(byte[] raw) throws IOException;
void writeOffer(org.briarproject.api.sync.Offer o) throws IOException;
void writeRequest(Request r) throws IOException;
void writeRetentionAck(org.briarproject.api.sync.RetentionAck a) throws IOException;
void writeRetentionUpdate(org.briarproject.api.sync.RetentionUpdate u) throws IOException;
void writeSubscriptionAck(org.briarproject.api.sync.SubscriptionAck a) throws IOException;
void writeSubscriptionUpdate(org.briarproject.api.sync.SubscriptionUpdate u) throws IOException;
void writeTransportAck(org.briarproject.api.sync.TransportAck a) throws IOException;
void writeTransportUpdate(org.briarproject.api.sync.TransportUpdate u) throws IOException;
void flush() throws IOException;
}

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.io.OutputStream; import java.io.OutputStream;

View File

@@ -0,0 +1,18 @@
package org.briarproject.api.sync;
import java.util.Collection;
/** A packet requesting one or more {@link Message}s from the recipient. */
public class Request {
private final Collection<org.briarproject.api.sync.MessageId> requested;
public Request(Collection<org.briarproject.api.sync.MessageId> requested) {
this.requested = requested;
}
/** Returns the identifiers of the requested messages. */
public Collection<org.briarproject.api.sync.MessageId> getMessageIds() {
return requested;
}
}

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
/** A packet acknowledging a (@link RetentionUpdate} */ /** A packet acknowledging a (@link RetentionUpdate} */
public class RetentionAck { public class RetentionAck {

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
/** /**
* A packet updating the recipient's view of the retention time of the sender's * A packet updating the recipient's view of the retention time of the sender's

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
/** A packet acknowledging a {@link SubscriptionUpdate}. */ /** A packet acknowledging a {@link SubscriptionUpdate}. */
public class SubscriptionAck { public class SubscriptionAck {

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import java.util.Collection; import java.util.Collection;

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
import org.briarproject.api.TransportProperties; import org.briarproject.api.TransportProperties;

View File

@@ -1,4 +1,4 @@
package org.briarproject.api.messaging; package org.briarproject.api.sync;
import org.briarproject.api.Author; import org.briarproject.api.Author;
@@ -6,14 +6,14 @@ import org.briarproject.api.Author;
public class UnverifiedMessage { public class UnverifiedMessage {
private final MessageId parent; private final MessageId parent;
private final Group group; private final org.briarproject.api.sync.Group group;
private final Author author; private final Author author;
private final String contentType; private final String contentType;
private final long timestamp; private final long timestamp;
private final byte[] raw, signature; private final byte[] raw, signature;
private final int bodyStart, bodyLength, signedLength; private final int bodyStart, bodyLength, signedLength;
public UnverifiedMessage(MessageId parent, Group group, Author author, public UnverifiedMessage(MessageId parent, org.briarproject.api.sync.Group group, Author author,
String contentType, long timestamp, byte[] raw, byte[] signature, String contentType, long timestamp, byte[] raw, byte[] signature,
int bodyStart, int bodyLength, int signedLength) { int bodyStart, int bodyLength, int signedLength) {
this.parent = parent; this.parent = parent;
@@ -37,10 +37,10 @@ public class UnverifiedMessage {
} }
/** /**
* Returns the {@link Group} to which the message belongs, or null if this * Returns the {@link org.briarproject.api.sync.Group} to which the message belongs, or null if this
* is a private message. * is a private message.
*/ */
public Group getGroup() { public org.briarproject.api.sync.Group getGroup() {
return group; return group;
} }

View File

@@ -10,17 +10,17 @@ import org.briarproject.api.TransportConfig;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
import org.briarproject.api.TransportProperties; import org.briarproject.api.TransportProperties;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.RetentionAck; import org.briarproject.api.sync.RetentionAck;
import org.briarproject.api.messaging.RetentionUpdate; import org.briarproject.api.sync.RetentionUpdate;
import org.briarproject.api.messaging.SubscriptionAck; import org.briarproject.api.sync.SubscriptionAck;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.transport.TransportKeys; import org.briarproject.api.transport.TransportKeys;
import java.io.IOException; import java.io.IOException;

View File

@@ -13,7 +13,6 @@ import org.briarproject.api.db.ContactExistsException;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.LocalAuthorExistsException; import org.briarproject.api.db.LocalAuthorExistsException;
import org.briarproject.api.db.MessageHeader;
import org.briarproject.api.db.NoSuchContactException; import org.briarproject.api.db.NoSuchContactException;
import org.briarproject.api.db.NoSuchLocalAuthorException; import org.briarproject.api.db.NoSuchLocalAuthorException;
import org.briarproject.api.db.NoSuchMessageException; import org.briarproject.api.db.NoSuchMessageException;
@@ -42,19 +41,20 @@ import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.event.TransportAddedEvent; import org.briarproject.api.event.TransportAddedEvent;
import org.briarproject.api.event.TransportRemovedEvent; import org.briarproject.api.event.TransportRemovedEvent;
import org.briarproject.api.lifecycle.ShutdownManager; import org.briarproject.api.lifecycle.ShutdownManager;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.messaging.Offer; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.Request; import org.briarproject.api.sync.Offer;
import org.briarproject.api.messaging.RetentionAck; import org.briarproject.api.sync.Request;
import org.briarproject.api.messaging.RetentionUpdate; import org.briarproject.api.sync.RetentionAck;
import org.briarproject.api.messaging.SubscriptionAck; import org.briarproject.api.sync.RetentionUpdate;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionAck;
import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.transport.TransportKeys; import org.briarproject.api.transport.TransportKeys;
import java.io.IOException; import java.io.IOException;

View File

@@ -12,18 +12,18 @@ import org.briarproject.api.TransportProperties;
import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.crypto.SecretKey;
import org.briarproject.api.db.DbClosedException; import org.briarproject.api.db.DbClosedException;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.sync.Group;
import org.briarproject.api.db.MessageHeader.State; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.MessageHeader.State;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.RetentionAck; import org.briarproject.api.sync.RetentionAck;
import org.briarproject.api.messaging.RetentionUpdate; import org.briarproject.api.sync.RetentionUpdate;
import org.briarproject.api.messaging.SubscriptionAck; import org.briarproject.api.sync.SubscriptionAck;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.api.transport.IncomingKeys; import org.briarproject.api.transport.IncomingKeys;
import org.briarproject.api.transport.OutgoingKeys; import org.briarproject.api.transport.OutgoingKeys;
@@ -57,8 +57,8 @@ import static java.util.logging.Level.WARNING;
import static org.briarproject.api.Author.Status.ANONYMOUS; import static org.briarproject.api.Author.Status.ANONYMOUS;
import static org.briarproject.api.Author.Status.UNKNOWN; import static org.briarproject.api.Author.Status.UNKNOWN;
import static org.briarproject.api.Author.Status.VERIFIED; import static org.briarproject.api.Author.Status.VERIFIED;
import static org.briarproject.api.messaging.MessagingConstants.MAX_SUBSCRIPTIONS; import static org.briarproject.api.sync.MessagingConstants.MAX_SUBSCRIPTIONS;
import static org.briarproject.api.messaging.MessagingConstants.RETENTION_GRANULARITY; import static org.briarproject.api.sync.MessagingConstants.RETENTION_GRANULARITY;
import static org.briarproject.db.ExponentialBackoff.calculateExpiry; import static org.briarproject.db.ExponentialBackoff.calculateExpiry;
/** /**
@@ -2675,7 +2675,6 @@ abstract class JdbcDatabase implements Database<Connection> {
public void raiseRequestedFlag(Connection txn, ContactId c, MessageId m) public void raiseRequestedFlag(Connection txn, ContactId c, MessageId m)
throws DbException { throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null;
try { try {
String sql = "UPDATE statuses SET requested = TRUE" String sql = "UPDATE statuses SET requested = TRUE"
+ " WHERE messageId = ? AND contactId = ?"; + " WHERE messageId = ? AND contactId = ?";
@@ -2686,7 +2685,6 @@ abstract class JdbcDatabase implements Database<Connection> {
if (affected < 0 || affected > 1) throw new DbStateException(); if (affected < 0 || affected > 1) throw new DbStateException();
ps.close(); ps.close();
} catch (SQLException e) { } catch (SQLException e) {
tryToClose(rs);
tryToClose(ps); tryToClose(ps);
throw new DbException(e); throw new DbException(e);
} }
@@ -2695,7 +2693,6 @@ abstract class JdbcDatabase implements Database<Connection> {
public void raiseSeenFlag(Connection txn, ContactId c, MessageId m) public void raiseSeenFlag(Connection txn, ContactId c, MessageId m)
throws DbException { throws DbException {
PreparedStatement ps = null; PreparedStatement ps = null;
ResultSet rs = null;
try { try {
String sql = "UPDATE statuses SET seen = TRUE" String sql = "UPDATE statuses SET seen = TRUE"
+ " WHERE messageId = ? AND contactId = ?"; + " WHERE messageId = ? AND contactId = ?";
@@ -2706,7 +2703,6 @@ abstract class JdbcDatabase implements Database<Connection> {
if (affected < 0 || affected > 1) throw new DbStateException(); if (affected < 0 || affected > 1) throw new DbStateException();
ps.close(); ps.close();
} catch (SQLException e) { } catch (SQLException e) {
tryToClose(rs);
tryToClose(ps); tryToClose(ps);
throw new DbException(e); throw new DbException(e);
} }

View File

@@ -14,10 +14,10 @@ import org.briarproject.api.data.Writer;
import org.briarproject.api.data.WriterFactory; import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.api.plugins.ConnectionManager; import org.briarproject.api.plugins.ConnectionManager;
import org.briarproject.api.plugins.duplex.DuplexPlugin; import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.plugins.duplex.DuplexTransportConnection; import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.api.transport.KeyManager; import org.briarproject.api.transport.KeyManager;
import org.briarproject.api.transport.StreamReaderFactory; import org.briarproject.api.transport.StreamReaderFactory;

View File

@@ -14,10 +14,10 @@ import org.briarproject.api.data.Writer;
import org.briarproject.api.data.WriterFactory; import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.api.plugins.ConnectionManager; import org.briarproject.api.plugins.ConnectionManager;
import org.briarproject.api.plugins.duplex.DuplexPlugin; import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.plugins.duplex.DuplexTransportConnection; import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.api.transport.KeyManager; import org.briarproject.api.transport.KeyManager;
import org.briarproject.api.transport.StreamReaderFactory; import org.briarproject.api.transport.StreamReaderFactory;

View File

@@ -20,11 +20,11 @@ import org.briarproject.api.data.Writer;
import org.briarproject.api.data.WriterFactory; import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.api.plugins.ConnectionManager; import org.briarproject.api.plugins.ConnectionManager;
import org.briarproject.api.plugins.duplex.DuplexPlugin; import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.plugins.duplex.DuplexTransportConnection; import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.api.transport.KeyManager; import org.briarproject.api.transport.KeyManager;
import org.briarproject.api.transport.StreamReaderFactory; import org.briarproject.api.transport.StreamReaderFactory;

View File

@@ -15,10 +15,10 @@ import org.briarproject.api.db.DbException;
import org.briarproject.api.invitation.InvitationListener; import org.briarproject.api.invitation.InvitationListener;
import org.briarproject.api.invitation.InvitationState; import org.briarproject.api.invitation.InvitationState;
import org.briarproject.api.invitation.InvitationTask; import org.briarproject.api.invitation.InvitationTask;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.api.plugins.ConnectionManager; import org.briarproject.api.plugins.ConnectionManager;
import org.briarproject.api.plugins.PluginManager; import org.briarproject.api.plugins.PluginManager;
import org.briarproject.api.plugins.duplex.DuplexPlugin; import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.api.transport.KeyManager; import org.briarproject.api.transport.KeyManager;
import org.briarproject.api.transport.StreamReaderFactory; import org.briarproject.api.transport.StreamReaderFactory;

View File

@@ -1,7 +1,5 @@
package org.briarproject.invitation; package org.briarproject.invitation;
import javax.inject.Inject;
import org.briarproject.api.AuthorFactory; import org.briarproject.api.AuthorFactory;
import org.briarproject.api.AuthorId; import org.briarproject.api.AuthorId;
import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.CryptoComponent;
@@ -10,14 +8,16 @@ import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.invitation.InvitationTask; import org.briarproject.api.invitation.InvitationTask;
import org.briarproject.api.invitation.InvitationTaskFactory; import org.briarproject.api.invitation.InvitationTaskFactory;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.api.plugins.ConnectionManager; import org.briarproject.api.plugins.ConnectionManager;
import org.briarproject.api.plugins.PluginManager; import org.briarproject.api.plugins.PluginManager;
import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.api.transport.KeyManager; import org.briarproject.api.transport.KeyManager;
import org.briarproject.api.transport.StreamReaderFactory; import org.briarproject.api.transport.StreamReaderFactory;
import org.briarproject.api.transport.StreamWriterFactory; import org.briarproject.api.transport.StreamWriterFactory;
import javax.inject.Inject;
class InvitationTaskFactoryImpl implements InvitationTaskFactory { class InvitationTaskFactoryImpl implements InvitationTaskFactory {
private final CryptoComponent crypto; private final CryptoComponent crypto;

View File

@@ -1,6 +0,0 @@
package org.briarproject.messaging;
interface ThrowingRunnable<T extends Throwable> {
public void run() throws T;
}

View File

@@ -1,7 +1,20 @@
package org.briarproject.plugins; package org.briarproject.plugins;
import static java.util.logging.Level.WARNING; import org.briarproject.api.ContactId;
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH; import org.briarproject.api.TransportId;
import org.briarproject.api.db.DbException;
import org.briarproject.api.lifecycle.IoExecutor;
import org.briarproject.api.plugins.ConnectionManager;
import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.api.plugins.TransportConnectionReader;
import org.briarproject.api.plugins.TransportConnectionWriter;
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
import org.briarproject.api.sync.MessagingSession;
import org.briarproject.api.sync.MessagingSessionFactory;
import org.briarproject.api.transport.KeyManager;
import org.briarproject.api.transport.StreamContext;
import org.briarproject.api.transport.StreamReaderFactory;
import org.briarproject.api.transport.StreamWriterFactory;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
@@ -12,21 +25,8 @@ import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import org.briarproject.api.ContactId; import static java.util.logging.Level.WARNING;
import org.briarproject.api.TransportId; import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
import org.briarproject.api.db.DbException;
import org.briarproject.api.lifecycle.IoExecutor;
import org.briarproject.api.messaging.MessagingSession;
import org.briarproject.api.messaging.MessagingSessionFactory;
import org.briarproject.api.plugins.ConnectionManager;
import org.briarproject.api.plugins.ConnectionRegistry;
import org.briarproject.api.plugins.TransportConnectionReader;
import org.briarproject.api.plugins.TransportConnectionWriter;
import org.briarproject.api.plugins.duplex.DuplexTransportConnection;
import org.briarproject.api.transport.KeyManager;
import org.briarproject.api.transport.StreamContext;
import org.briarproject.api.transport.StreamReaderFactory;
import org.briarproject.api.transport.StreamWriterFactory;
class ConnectionManagerImpl implements ConnectionManager { class ConnectionManagerImpl implements ConnectionManager {

View File

@@ -1,9 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.inject.Inject;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.AuthorFactory; import org.briarproject.api.AuthorFactory;
@@ -15,6 +10,11 @@ import org.briarproject.api.data.Writer;
import org.briarproject.api.data.WriterFactory; import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.inject.Inject;
class AuthorFactoryImpl implements AuthorFactory { class AuthorFactoryImpl implements AuthorFactory {
private final CryptoComponent crypto; private final CryptoComponent crypto;

View File

@@ -1,9 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import java.io.IOException;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.AuthorId; import org.briarproject.api.AuthorId;
@@ -13,6 +8,11 @@ import org.briarproject.api.crypto.MessageDigest;
import org.briarproject.api.data.ObjectReader; import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.data.Reader; import org.briarproject.api.data.Reader;
import java.io.IOException;
import static org.briarproject.api.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
class AuthorReader implements ObjectReader<Author> { class AuthorReader implements ObjectReader<Author> {
private final MessageDigest messageDigest; private final MessageDigest messageDigest;

View File

@@ -1,10 +1,10 @@
package org.briarproject.messaging; package org.briarproject.sync;
import org.briarproject.api.data.Consumer;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import org.briarproject.api.data.Consumer;
/** A consumer that makes a copy of the bytes consumed. */ /** A consumer that makes a copy of the bytes consumed. */
class CopyingConsumer implements Consumer { class CopyingConsumer implements Consumer {

View File

@@ -1,10 +1,10 @@
package org.briarproject.messaging; package org.briarproject.sync;
import java.io.IOException;
import org.briarproject.api.FormatException; import org.briarproject.api.FormatException;
import org.briarproject.api.data.Consumer; import org.briarproject.api.data.Consumer;
import java.io.IOException;
/** /**
* A consumer that counts the number of bytes consumed and throws a * A consumer that counts the number of bytes consumed and throws a
* FormatException if the count exceeds a given limit. * FormatException if the count exceeds a given limit.

View File

@@ -1,4 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import org.briarproject.api.crypto.MessageDigest; import org.briarproject.api.crypto.MessageDigest;
import org.briarproject.api.data.Consumer; import org.briarproject.api.data.Consumer;

View File

@@ -1,16 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Logger;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
@@ -32,21 +20,33 @@ import org.briarproject.api.event.RemoteSubscriptionsUpdatedEvent;
import org.briarproject.api.event.RemoteTransportsUpdatedEvent; import org.briarproject.api.event.RemoteTransportsUpdatedEvent;
import org.briarproject.api.event.ShutdownEvent; import org.briarproject.api.event.ShutdownEvent;
import org.briarproject.api.event.TransportRemovedEvent; import org.briarproject.api.event.TransportRemovedEvent;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.MessagingSession; import org.briarproject.api.sync.MessagingSession;
import org.briarproject.api.messaging.Offer; import org.briarproject.api.sync.Offer;
import org.briarproject.api.messaging.PacketWriter; import org.briarproject.api.sync.PacketWriter;
import org.briarproject.api.messaging.Request; import org.briarproject.api.sync.Request;
import org.briarproject.api.messaging.RetentionAck; import org.briarproject.api.sync.RetentionAck;
import org.briarproject.api.messaging.RetentionUpdate; import org.briarproject.api.sync.RetentionUpdate;
import org.briarproject.api.messaging.SubscriptionAck; import org.briarproject.api.sync.SubscriptionAck;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Logger;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
/** /**
* An outgoing {@link org.briarproject.api.messaging.MessagingSession * An outgoing {@link MessagingSession
* MessagingSession} suitable for duplex transports. The session offers * MessagingSession} suitable for duplex transports. The session offers
* messages before sending them, keeps its output stream open when there are no * messages before sending them, keeps its output stream open when there are no
* packets to send, and reacts to events that make packets available to send. * packets to send, and reacts to events that make packets available to send.

View File

@@ -1,19 +1,19 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH; import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.crypto.MessageDigest;
import org.briarproject.api.data.Writer;
import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.sync.GroupId;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import javax.inject.Inject; import javax.inject.Inject;
import org.briarproject.api.crypto.CryptoComponent; import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
import org.briarproject.api.crypto.MessageDigest;
import org.briarproject.api.data.Writer;
import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupFactory;
import org.briarproject.api.messaging.GroupId;
class GroupFactoryImpl implements GroupFactory { class GroupFactoryImpl implements GroupFactory {

View File

@@ -1,17 +1,17 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH;
import java.io.IOException;
import org.briarproject.api.FormatException; import org.briarproject.api.FormatException;
import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.crypto.MessageDigest; import org.briarproject.api.crypto.MessageDigest;
import org.briarproject.api.data.ObjectReader; import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.data.Reader; import org.briarproject.api.data.Reader;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import java.io.IOException;
import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MAX_GROUP_NAME_LENGTH;
class GroupReader implements ObjectReader<Group> { class GroupReader implements ObjectReader<Group> {

View File

@@ -1,11 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static java.util.logging.Level.WARNING;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.FormatException; import org.briarproject.api.FormatException;
@@ -18,23 +11,30 @@ import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.ShutdownEvent; import org.briarproject.api.event.ShutdownEvent;
import org.briarproject.api.event.TransportRemovedEvent; import org.briarproject.api.event.TransportRemovedEvent;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.sync.MessageVerifier;
import org.briarproject.api.messaging.MessagingSession; import org.briarproject.api.sync.MessagingSession;
import org.briarproject.api.messaging.Offer; import org.briarproject.api.sync.Offer;
import org.briarproject.api.messaging.PacketReader; import org.briarproject.api.sync.PacketReader;
import org.briarproject.api.messaging.Request; import org.briarproject.api.sync.Request;
import org.briarproject.api.messaging.RetentionAck; import org.briarproject.api.sync.RetentionAck;
import org.briarproject.api.messaging.RetentionUpdate; import org.briarproject.api.sync.RetentionUpdate;
import org.briarproject.api.messaging.SubscriptionAck; import org.briarproject.api.sync.SubscriptionAck;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.messaging.UnverifiedMessage; import org.briarproject.api.sync.UnverifiedMessage;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import static java.util.logging.Level.WARNING;
/** /**
* An incoming {@link org.briarproject.api.messaging.MessagingSession * An incoming {@link MessagingSession
* MessagingSession}. * MessagingSession}.
*/ */
class IncomingSession implements MessagingSession, EventListener { class IncomingSession implements MessagingSession, EventListener {

View File

@@ -1,17 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_BODY_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MESSAGE_SALT_LENGTH;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import javax.inject.Inject;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.CryptoComponent;
@@ -21,12 +8,25 @@ import org.briarproject.api.crypto.Signature;
import org.briarproject.api.data.Consumer; import org.briarproject.api.data.Consumer;
import org.briarproject.api.data.Writer; import org.briarproject.api.data.Writer;
import org.briarproject.api.data.WriterFactory; import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageFactory; import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import javax.inject.Inject;
import static org.briarproject.api.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MAX_BODY_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MESSAGE_SALT_LENGTH;
class MessageFactoryImpl implements MessageFactory { class MessageFactoryImpl implements MessageFactory {
private final Signature signature; private final Signature signature;
@@ -78,7 +78,7 @@ class MessageFactoryImpl implements MessageFactory {
Consumer signingConsumer = null; Consumer signingConsumer = null;
if (privateKey != null) { if (privateKey != null) {
signature.initSign(privateKey); signature.initSign(privateKey);
signingConsumer = new SigningConsumer(signature); signingConsumer = new org.briarproject.sync.SigningConsumer(signature);
w.addConsumer(signingConsumer); w.addConsumer(signingConsumer);
} }
// Write the message // Write the message
@@ -109,7 +109,7 @@ class MessageFactoryImpl implements MessageFactory {
// Hash the message, including the signature, to get the message ID // Hash the message, including the signature, to get the message ID
w.removeConsumer(digestingConsumer); w.removeConsumer(digestingConsumer);
MessageId id = new MessageId(messageDigest.digest()); MessageId id = new MessageId(messageDigest.digest());
return new MessageImpl(id, parent, group, author, contentType, return new org.briarproject.sync.MessageImpl(id, parent, group, author, contentType,
timestamp, out.toByteArray(), bodyStart, body.length); timestamp, out.toByteArray(), bodyStart, body.length);
} }

View File

@@ -1,11 +1,11 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.messaging.MessagingConstants.MAX_BODY_LENGTH;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import static org.briarproject.api.sync.MessagingConstants.MAX_BODY_LENGTH;
/** A simple in-memory implementation of a message. */ /** A simple in-memory implementation of a message. */
class MessageImpl implements Message { class MessageImpl implements Message {

View File

@@ -1,21 +1,21 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_BODY_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MESSAGE_SALT_LENGTH;
import java.io.IOException;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.FormatException; import org.briarproject.api.FormatException;
import org.briarproject.api.UniqueId; import org.briarproject.api.UniqueId;
import org.briarproject.api.data.ObjectReader; import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.data.Reader; import org.briarproject.api.data.Reader;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.UnverifiedMessage; import org.briarproject.api.sync.UnverifiedMessage;
import java.io.IOException;
import static org.briarproject.api.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MAX_BODY_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
import static org.briarproject.api.sync.MessagingConstants.MESSAGE_SALT_LENGTH;
class MessageReader implements ObjectReader<UnverifiedMessage> { class MessageReader implements ObjectReader<UnverifiedMessage> {

View File

@@ -1,12 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static java.util.logging.Level.INFO;
import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
import java.security.GeneralSecurityException;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.CryptoComponent;
@@ -14,12 +6,20 @@ import org.briarproject.api.crypto.KeyParser;
import org.briarproject.api.crypto.MessageDigest; import org.briarproject.api.crypto.MessageDigest;
import org.briarproject.api.crypto.PublicKey; import org.briarproject.api.crypto.PublicKey;
import org.briarproject.api.crypto.Signature; import org.briarproject.api.crypto.Signature;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.sync.MessageVerifier;
import org.briarproject.api.messaging.UnverifiedMessage; import org.briarproject.api.sync.UnverifiedMessage;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import java.security.GeneralSecurityException;
import java.util.logging.Logger;
import javax.inject.Inject;
import static java.util.logging.Level.INFO;
import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
class MessageVerifierImpl implements MessageVerifier { class MessageVerifierImpl implements MessageVerifier {
private static final Logger LOG = private static final Logger LOG =

View File

@@ -1,23 +1,23 @@
package org.briarproject.messaging; package org.briarproject.sync;
import javax.inject.Singleton; import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.AuthorFactory; import org.briarproject.api.AuthorFactory;
import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.data.ObjectReader; import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupFactory; import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.messaging.MessageFactory; import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.sync.MessageVerifier;
import org.briarproject.api.messaging.MessagingSessionFactory; import org.briarproject.api.sync.MessagingSessionFactory;
import org.briarproject.api.messaging.PacketReaderFactory; import org.briarproject.api.sync.PacketReaderFactory;
import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.sync.PacketWriterFactory;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.UnverifiedMessage; import org.briarproject.api.sync.UnverifiedMessage;
import com.google.inject.AbstractModule; import javax.inject.Singleton;
import com.google.inject.Provides;
public class MessagingModule extends AbstractModule { public class MessagingModule extends AbstractModule {
@@ -47,7 +47,7 @@ public class MessagingModule extends AbstractModule {
ObjectReader<UnverifiedMessage> getMessageReader( ObjectReader<UnverifiedMessage> getMessageReader(
ObjectReader<Group> groupReader, ObjectReader<Group> groupReader,
ObjectReader<Author> authorReader) { ObjectReader<Author> authorReader) {
return new MessageReader(groupReader, authorReader); return new org.briarproject.sync.MessageReader(groupReader, authorReader);
} }
@Provides @Provides

View File

@@ -1,10 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
@@ -12,15 +6,21 @@ import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.db.DatabaseExecutor; import org.briarproject.api.db.DatabaseExecutor;
import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventBus;
import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.sync.MessageVerifier;
import org.briarproject.api.messaging.MessagingSession; import org.briarproject.api.sync.MessagingSession;
import org.briarproject.api.messaging.MessagingSessionFactory; import org.briarproject.api.sync.MessagingSessionFactory;
import org.briarproject.api.messaging.PacketReader; import org.briarproject.api.sync.PacketReader;
import org.briarproject.api.messaging.PacketReaderFactory; import org.briarproject.api.sync.PacketReaderFactory;
import org.briarproject.api.messaging.PacketWriter; import org.briarproject.api.sync.PacketWriter;
import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.sync.PacketWriterFactory;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.concurrent.Executor;
import javax.inject.Inject;
class MessagingSessionFactoryImpl implements MessagingSessionFactory { class MessagingSessionFactoryImpl implements MessagingSessionFactory {
private final DatabaseComponent db; private final DatabaseComponent db;

View File

@@ -1,16 +1,16 @@
package org.briarproject.messaging; package org.briarproject.sync;
import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.data.ReaderFactory;
import org.briarproject.api.sync.PacketReader;
import org.briarproject.api.sync.PacketReaderFactory;
import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.sync.UnverifiedMessage;
import java.io.InputStream; import java.io.InputStream;
import javax.inject.Inject; import javax.inject.Inject;
import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.data.ReaderFactory;
import org.briarproject.api.messaging.PacketReader;
import org.briarproject.api.messaging.PacketReaderFactory;
import org.briarproject.api.messaging.SubscriptionUpdate;
import org.briarproject.api.messaging.UnverifiedMessage;
class PacketReaderFactoryImpl implements PacketReaderFactory { class PacketReaderFactoryImpl implements PacketReaderFactory {
private final ReaderFactory readerFactory; private final ReaderFactory readerFactory;

View File

@@ -1,21 +1,25 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT; import org.briarproject.api.FormatException;
import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTY_LENGTH; import org.briarproject.api.TransportId;
import static org.briarproject.api.TransportPropertyConstants.MAX_TRANSPORT_ID_LENGTH; import org.briarproject.api.TransportProperties;
import static org.briarproject.api.messaging.MessagingConstants.HEADER_LENGTH; import org.briarproject.api.UniqueId;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH; import org.briarproject.api.data.ObjectReader;
import static org.briarproject.api.messaging.MessagingConstants.PROTOCOL_VERSION; import org.briarproject.api.data.Reader;
import static org.briarproject.api.messaging.PacketTypes.ACK; import org.briarproject.api.data.ReaderFactory;
import static org.briarproject.api.messaging.PacketTypes.MESSAGE; import org.briarproject.api.sync.Ack;
import static org.briarproject.api.messaging.PacketTypes.OFFER; import org.briarproject.api.sync.MessageId;
import static org.briarproject.api.messaging.PacketTypes.REQUEST; import org.briarproject.api.sync.Offer;
import static org.briarproject.api.messaging.PacketTypes.RETENTION_ACK; import org.briarproject.api.sync.PacketReader;
import static org.briarproject.api.messaging.PacketTypes.RETENTION_UPDATE; import org.briarproject.api.sync.Request;
import static org.briarproject.api.messaging.PacketTypes.SUBSCRIPTION_ACK; import org.briarproject.api.sync.RetentionAck;
import static org.briarproject.api.messaging.PacketTypes.SUBSCRIPTION_UPDATE; import org.briarproject.api.sync.RetentionUpdate;
import static org.briarproject.api.messaging.PacketTypes.TRANSPORT_ACK; import org.briarproject.api.sync.SubscriptionAck;
import static org.briarproject.api.messaging.PacketTypes.TRANSPORT_UPDATE; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.sync.UnverifiedMessage;
import org.briarproject.util.ByteUtils;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
@@ -26,31 +30,27 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.briarproject.api.FormatException; import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT;
import org.briarproject.api.TransportId; import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTY_LENGTH;
import org.briarproject.api.TransportProperties; import static org.briarproject.api.TransportPropertyConstants.MAX_TRANSPORT_ID_LENGTH;
import org.briarproject.api.UniqueId; import static org.briarproject.api.sync.MessagingConstants.HEADER_LENGTH;
import org.briarproject.api.data.ObjectReader; import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
import org.briarproject.api.data.Reader; import static org.briarproject.api.sync.MessagingConstants.PROTOCOL_VERSION;
import org.briarproject.api.data.ReaderFactory; import static org.briarproject.api.sync.PacketTypes.ACK;
import org.briarproject.api.messaging.Ack; import static org.briarproject.api.sync.PacketTypes.MESSAGE;
import org.briarproject.api.messaging.MessageId; import static org.briarproject.api.sync.PacketTypes.OFFER;
import org.briarproject.api.messaging.Offer; import static org.briarproject.api.sync.PacketTypes.REQUEST;
import org.briarproject.api.messaging.PacketReader; import static org.briarproject.api.sync.PacketTypes.RETENTION_ACK;
import org.briarproject.api.messaging.Request; import static org.briarproject.api.sync.PacketTypes.RETENTION_UPDATE;
import org.briarproject.api.messaging.RetentionAck; import static org.briarproject.api.sync.PacketTypes.SUBSCRIPTION_ACK;
import org.briarproject.api.messaging.RetentionUpdate; import static org.briarproject.api.sync.PacketTypes.SUBSCRIPTION_UPDATE;
import org.briarproject.api.messaging.SubscriptionAck; import static org.briarproject.api.sync.PacketTypes.TRANSPORT_ACK;
import org.briarproject.api.messaging.SubscriptionUpdate; import static org.briarproject.api.sync.PacketTypes.TRANSPORT_UPDATE;
import org.briarproject.api.messaging.TransportAck;
import org.briarproject.api.messaging.TransportUpdate;
import org.briarproject.api.messaging.UnverifiedMessage;
import org.briarproject.util.ByteUtils;
// This class is not thread-safe // This class is not thread-safe
class PacketReaderImpl implements PacketReader { class PacketReaderImpl implements PacketReader {
private enum State { BUFFER_EMPTY, BUFFER_FULL, EOF }; private enum State { BUFFER_EMPTY, BUFFER_FULL, EOF }
private final ReaderFactory readerFactory; private final ReaderFactory readerFactory;
private final ObjectReader<UnverifiedMessage> messageReader; private final ObjectReader<UnverifiedMessage> messageReader;

View File

@@ -1,13 +1,13 @@
package org.briarproject.messaging; package org.briarproject.sync;
import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.sync.PacketWriter;
import org.briarproject.api.sync.PacketWriterFactory;
import java.io.OutputStream; import java.io.OutputStream;
import javax.inject.Inject; import javax.inject.Inject;
import org.briarproject.api.data.WriterFactory;
import org.briarproject.api.messaging.PacketWriter;
import org.briarproject.api.messaging.PacketWriterFactory;
class PacketWriterFactoryImpl implements PacketWriterFactory { class PacketWriterFactoryImpl implements PacketWriterFactory {
private final WriterFactory writerFactory; private final WriterFactory writerFactory;

View File

@@ -1,41 +1,41 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.data.DataConstants.LIST_END_LENGTH; import org.briarproject.api.data.Writer;
import static org.briarproject.api.data.DataConstants.LIST_START_LENGTH; import org.briarproject.api.data.WriterFactory;
import static org.briarproject.api.data.DataConstants.UNIQUE_ID_LENGTH; import org.briarproject.api.sync.Ack;
import static org.briarproject.api.messaging.MessagingConstants.HEADER_LENGTH; import org.briarproject.api.sync.Group;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH; import org.briarproject.api.sync.MessageId;
import static org.briarproject.api.messaging.MessagingConstants.PROTOCOL_VERSION; import org.briarproject.api.sync.Offer;
import static org.briarproject.api.messaging.PacketTypes.ACK; import org.briarproject.api.sync.PacketTypes;
import static org.briarproject.api.messaging.PacketTypes.OFFER; import org.briarproject.api.sync.PacketWriter;
import static org.briarproject.api.messaging.PacketTypes.REQUEST; import org.briarproject.api.sync.Request;
import static org.briarproject.api.messaging.PacketTypes.RETENTION_ACK; import org.briarproject.api.sync.RetentionAck;
import static org.briarproject.api.messaging.PacketTypes.RETENTION_UPDATE; import org.briarproject.api.sync.RetentionUpdate;
import static org.briarproject.api.messaging.PacketTypes.SUBSCRIPTION_ACK; import org.briarproject.api.sync.SubscriptionAck;
import static org.briarproject.api.messaging.PacketTypes.SUBSCRIPTION_UPDATE; import org.briarproject.api.sync.SubscriptionUpdate;
import static org.briarproject.api.messaging.PacketTypes.TRANSPORT_ACK; import org.briarproject.api.sync.TransportAck;
import static org.briarproject.api.messaging.PacketTypes.TRANSPORT_UPDATE; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.util.ByteUtils;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.briarproject.api.data.Writer; import static org.briarproject.api.data.DataConstants.LIST_END_LENGTH;
import org.briarproject.api.data.WriterFactory; import static org.briarproject.api.data.DataConstants.LIST_START_LENGTH;
import org.briarproject.api.messaging.Ack; import static org.briarproject.api.data.DataConstants.UNIQUE_ID_LENGTH;
import org.briarproject.api.messaging.Group; import static org.briarproject.api.sync.MessagingConstants.HEADER_LENGTH;
import org.briarproject.api.messaging.MessageId; import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
import org.briarproject.api.messaging.Offer; import static org.briarproject.api.sync.MessagingConstants.PROTOCOL_VERSION;
import org.briarproject.api.messaging.PacketTypes; import static org.briarproject.api.sync.PacketTypes.ACK;
import org.briarproject.api.messaging.PacketWriter; import static org.briarproject.api.sync.PacketTypes.OFFER;
import org.briarproject.api.messaging.Request; import static org.briarproject.api.sync.PacketTypes.REQUEST;
import org.briarproject.api.messaging.RetentionAck; import static org.briarproject.api.sync.PacketTypes.RETENTION_ACK;
import org.briarproject.api.messaging.RetentionUpdate; import static org.briarproject.api.sync.PacketTypes.RETENTION_UPDATE;
import org.briarproject.api.messaging.SubscriptionAck; import static org.briarproject.api.sync.PacketTypes.SUBSCRIPTION_ACK;
import org.briarproject.api.messaging.SubscriptionUpdate; import static org.briarproject.api.sync.PacketTypes.SUBSCRIPTION_UPDATE;
import org.briarproject.api.messaging.TransportAck; import static org.briarproject.api.sync.PacketTypes.TRANSPORT_ACK;
import org.briarproject.api.messaging.TransportUpdate; import static org.briarproject.api.sync.PacketTypes.TRANSPORT_UPDATE;
import org.briarproject.util.ByteUtils;
// This class is not thread-safe // This class is not thread-safe
class PacketWriterImpl implements PacketWriter { class PacketWriterImpl implements PacketWriter {

View File

@@ -1,4 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import org.briarproject.api.crypto.Signature; import org.briarproject.api.crypto.Signature;
import org.briarproject.api.data.Consumer; import org.briarproject.api.data.Consumer;

View File

@@ -1,16 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
import org.briarproject.api.ContactId; import org.briarproject.api.ContactId;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
@@ -22,18 +10,30 @@ import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.ShutdownEvent; import org.briarproject.api.event.ShutdownEvent;
import org.briarproject.api.event.TransportRemovedEvent; import org.briarproject.api.event.TransportRemovedEvent;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.MessagingSession; import org.briarproject.api.sync.MessagingSession;
import org.briarproject.api.messaging.PacketWriter; import org.briarproject.api.sync.PacketWriter;
import org.briarproject.api.messaging.RetentionAck; import org.briarproject.api.sync.RetentionAck;
import org.briarproject.api.messaging.RetentionUpdate; import org.briarproject.api.sync.RetentionUpdate;
import org.briarproject.api.messaging.SubscriptionAck; import org.briarproject.api.sync.SubscriptionAck;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
/** /**
* An outgoing {@link org.briarproject.api.messaging.MessagingSession * An outgoing {@link MessagingSession
* MessagingSession} suitable for simplex transports. The session sends * MessagingSession} suitable for simplex transports. The session sends
* messages without offering them, and closes its output stream when there are * messages without offering them, and closes its output stream when there are
* no more packets to send. * no more packets to send.

View File

@@ -1,7 +1,12 @@
package org.briarproject.messaging; package org.briarproject.sync;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH; import org.briarproject.api.FormatException;
import static org.briarproject.api.messaging.MessagingConstants.MAX_SUBSCRIPTIONS; import org.briarproject.api.data.Consumer;
import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.data.Reader;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.GroupId;
import org.briarproject.api.sync.SubscriptionUpdate;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -10,13 +15,8 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.briarproject.api.FormatException; import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
import org.briarproject.api.data.Consumer; import static org.briarproject.api.sync.MessagingConstants.MAX_SUBSCRIPTIONS;
import org.briarproject.api.data.ObjectReader;
import org.briarproject.api.data.Reader;
import org.briarproject.api.messaging.Group;
import org.briarproject.api.messaging.GroupId;
import org.briarproject.api.messaging.SubscriptionUpdate;
class SubscriptionUpdateReader implements ObjectReader<SubscriptionUpdate> { class SubscriptionUpdateReader implements ObjectReader<SubscriptionUpdate> {

View File

@@ -0,0 +1,6 @@
package org.briarproject.sync;
interface ThrowingRunnable<T extends Throwable> {
void run() throws T;
}

View File

@@ -11,22 +11,22 @@ import org.briarproject.api.TransportProperties;
import org.briarproject.api.crypto.CryptoComponent; import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.crypto.KeyPair; import org.briarproject.api.crypto.KeyPair;
import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.crypto.SecretKey;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupFactory; import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageFactory; import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.sync.MessageVerifier;
import org.briarproject.api.messaging.Offer; import org.briarproject.api.sync.Offer;
import org.briarproject.api.messaging.PacketReader; import org.briarproject.api.sync.PacketReader;
import org.briarproject.api.messaging.PacketReaderFactory; import org.briarproject.api.sync.PacketReaderFactory;
import org.briarproject.api.messaging.PacketWriter; import org.briarproject.api.sync.PacketWriter;
import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.sync.PacketWriterFactory;
import org.briarproject.api.messaging.Request; import org.briarproject.api.sync.Request;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.messaging.UnverifiedMessage; import org.briarproject.api.sync.UnverifiedMessage;
import org.briarproject.api.transport.StreamContext; import org.briarproject.api.transport.StreamContext;
import org.briarproject.api.transport.StreamReaderFactory; import org.briarproject.api.transport.StreamReaderFactory;
import org.briarproject.api.transport.StreamWriterFactory; import org.briarproject.api.transport.StreamWriterFactory;
@@ -34,7 +34,7 @@ import org.briarproject.crypto.CryptoModule;
import org.briarproject.data.DataModule; import org.briarproject.data.DataModule;
import org.briarproject.db.DatabaseModule; import org.briarproject.db.DatabaseModule;
import org.briarproject.event.EventModule; import org.briarproject.event.EventModule;
import org.briarproject.messaging.MessagingModule; import org.briarproject.sync.MessagingModule;
import org.briarproject.transport.TransportModule; import org.briarproject.transport.TransportModule;
import org.junit.Test; import org.junit.Test;

View File

@@ -1,9 +1,9 @@
package org.briarproject; package org.briarproject;
import org.briarproject.api.Author; import org.briarproject.api.Author;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;

View File

@@ -33,19 +33,19 @@ import org.briarproject.api.event.MessagesSentEvent;
import org.briarproject.api.event.SubscriptionAddedEvent; import org.briarproject.api.event.SubscriptionAddedEvent;
import org.briarproject.api.event.SubscriptionRemovedEvent; import org.briarproject.api.event.SubscriptionRemovedEvent;
import org.briarproject.api.lifecycle.ShutdownManager; import org.briarproject.api.lifecycle.ShutdownManager;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.Offer; import org.briarproject.api.sync.Offer;
import org.briarproject.api.messaging.Request; import org.briarproject.api.sync.Request;
import org.briarproject.api.messaging.RetentionAck; import org.briarproject.api.sync.RetentionAck;
import org.briarproject.api.messaging.RetentionUpdate; import org.briarproject.api.sync.RetentionUpdate;
import org.briarproject.api.messaging.SubscriptionAck; import org.briarproject.api.sync.SubscriptionAck;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportAck; import org.briarproject.api.sync.TransportAck;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.api.transport.IncomingKeys; import org.briarproject.api.transport.IncomingKeys;
import org.briarproject.api.transport.OutgoingKeys; import org.briarproject.api.transport.OutgoingKeys;
import org.briarproject.api.transport.TransportKeys; import org.briarproject.api.transport.TransportKeys;
@@ -58,7 +58,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH; import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
import static org.briarproject.db.DatabaseConstants.MAX_OFFERED_MESSAGES; import static org.briarproject.db.DatabaseConstants.MAX_OFFERED_MESSAGES;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@@ -335,137 +335,187 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try { try {
db.addTransportKeys(contactId, createTransportKeys()); db.addTransportKeys(contactId, createTransportKeys());
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateAck(contactId, 123); db.generateAck(contactId, 123);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateBatch(contactId, 123, 456); db.generateBatch(contactId, 123, 456);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateOffer(contactId, 123, 456); db.generateOffer(contactId, 123, 456);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateRetentionAck(contactId); db.generateRetentionAck(contactId);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateRetentionUpdate(contactId, 123); db.generateRetentionUpdate(contactId, 123);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateSubscriptionAck(contactId); db.generateSubscriptionAck(contactId);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateSubscriptionUpdate(contactId, 123); db.generateSubscriptionUpdate(contactId, 123);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateTransportAcks(contactId); db.generateTransportAcks(contactId);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.generateTransportUpdates(contactId, 123); db.generateTransportUpdates(contactId, 123);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.getContact(contactId); db.getContact(contactId);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.getInboxGroupId(contactId); db.getInboxGroupId(contactId);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.incrementStreamCounter(contactId, transportId, 0); db.incrementStreamCounter(contactId, transportId, 0);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
Ack a = new Ack(Collections.singletonList(messageId)); Ack a = new Ack(Collections.singletonList(messageId));
db.receiveAck(contactId, a); db.receiveAck(contactId, a);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.receiveMessage(contactId, message); db.receiveMessage(contactId, message);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
Offer o = new Offer(Collections.singletonList(messageId)); Offer o = new Offer(Collections.singletonList(messageId));
db.receiveOffer(contactId, o); db.receiveOffer(contactId, o);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
RetentionAck a = new RetentionAck(0); RetentionAck a = new RetentionAck(0);
db.receiveRetentionAck(contactId, a); db.receiveRetentionAck(contactId, a);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
RetentionUpdate u = new RetentionUpdate(0, 1); RetentionUpdate u = new RetentionUpdate(0, 1);
db.receiveRetentionUpdate(contactId, u); db.receiveRetentionUpdate(contactId, u);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
SubscriptionAck a = new SubscriptionAck(0); SubscriptionAck a = new SubscriptionAck(0);
db.receiveSubscriptionAck(contactId, a); db.receiveSubscriptionAck(contactId, a);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
SubscriptionUpdate u = new SubscriptionUpdate( SubscriptionUpdate u = new SubscriptionUpdate(
Collections.<Group>emptyList(), 1); Collections.<Group>emptyList(), 1);
db.receiveSubscriptionUpdate(contactId, u); db.receiveSubscriptionUpdate(contactId, u);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
TransportAck a = new TransportAck(transportId, 0); TransportAck a = new TransportAck(transportId, 0);
db.receiveTransportAck(contactId, a); db.receiveTransportAck(contactId, a);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
TransportUpdate u = new TransportUpdate(transportId, TransportUpdate u = new TransportUpdate(transportId,
transportProperties, 1); transportProperties, 1);
db.receiveTransportUpdate(contactId, u); db.receiveTransportUpdate(contactId, u);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.removeContact(contactId); db.removeContact(contactId);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]); db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
try { try {
db.setInboxGroup(contactId, group); db.setInboxGroup(contactId, group);
fail(); fail();
} catch (NoSuchContactException expected) {} } catch (NoSuchContactException expected) {
// Expected
}
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@@ -496,17 +546,23 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try { try {
db.addContact(author, localAuthorId); db.addContact(author, localAuthorId);
fail(); fail();
} catch (NoSuchLocalAuthorException expected) {} } catch (NoSuchLocalAuthorException expected) {
// Expected
}
try { try {
db.getLocalAuthor(localAuthorId); db.getLocalAuthor(localAuthorId);
fail(); fail();
} catch (NoSuchLocalAuthorException expected) {} } catch (NoSuchLocalAuthorException expected) {
// Expected
}
try { try {
db.removeLocalAuthor(localAuthorId); db.removeLocalAuthor(localAuthorId);
fail(); fail();
} catch (NoSuchLocalAuthorException expected) {} } catch (NoSuchLocalAuthorException expected) {
// Expected
}
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@@ -534,27 +590,37 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try { try {
db.getGroup(groupId); db.getGroup(groupId);
fail(); fail();
} catch (NoSuchSubscriptionException expected) {} } catch (NoSuchSubscriptionException expected) {
// Expected
}
try { try {
db.getMessageHeaders(groupId); db.getMessageHeaders(groupId);
fail(); fail();
} catch (NoSuchSubscriptionException expected) {} } catch (NoSuchSubscriptionException expected) {
// Expected
}
try { try {
db.getVisibility(groupId); db.getVisibility(groupId);
fail(); fail();
} catch (NoSuchSubscriptionException expected) {} } catch (NoSuchSubscriptionException expected) {
// Expected
}
try { try {
db.removeGroup(group); db.removeGroup(group);
fail(); fail();
} catch (NoSuchSubscriptionException expected) {} } catch (NoSuchSubscriptionException expected) {
// Expected
}
try { try {
db.setVisibility(groupId, Collections.<ContactId>emptyList()); db.setVisibility(groupId, Collections.<ContactId>emptyList());
fail(); fail();
} catch (NoSuchSubscriptionException expected) {} } catch (NoSuchSubscriptionException expected) {
// Expected
}
context.assertIsSatisfied(); context.assertIsSatisfied();
} }
@@ -606,42 +672,58 @@ public abstract class DatabaseComponentTest extends BriarTestCase {
try { try {
db.getConfig(transportId); db.getConfig(transportId);
fail(); fail();
} catch (NoSuchTransportException expected) {} } catch (NoSuchTransportException expected) {
// Expected
}
try { try {
db.getLocalProperties(transportId); db.getLocalProperties(transportId);
fail(); fail();
} catch (NoSuchTransportException expected) {} } catch (NoSuchTransportException expected) {
// Expected
}
try { try {
db.getTransportKeys(transportId); db.getTransportKeys(transportId);
fail(); fail();
} catch (NoSuchTransportException expected) {} } catch (NoSuchTransportException expected) {
// Expected
}
try { try {
db.mergeConfig(transportId, new TransportConfig()); db.mergeConfig(transportId, new TransportConfig());
fail(); fail();
} catch (NoSuchTransportException expected) {} } catch (NoSuchTransportException expected) {
// Expected
}
try { try {
db.mergeLocalProperties(transportId, new TransportProperties()); db.mergeLocalProperties(transportId, new TransportProperties());
fail(); fail();
} catch (NoSuchTransportException expected) {} } catch (NoSuchTransportException expected) {
// Expected
}
try { try {
db.incrementStreamCounter(contactId, transportId, 0); db.incrementStreamCounter(contactId, transportId, 0);
fail(); fail();
} catch (NoSuchTransportException expected) {} } catch (NoSuchTransportException expected) {
// Expected
}
try { try {
db.removeTransport(transportId); db.removeTransport(transportId);
fail(); fail();
} catch (NoSuchTransportException expected) {} } catch (NoSuchTransportException expected) {
// Expected
}
try { try {
db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]); db.setReorderingWindow(contactId, transportId, 0, 0, new byte[4]);
fail(); fail();
} catch (NoSuchTransportException expected) {} } catch (NoSuchTransportException expected) {
// Expected
}
context.assertIsSatisfied(); context.assertIsSatisfied();
} }

View File

@@ -13,11 +13,11 @@ import org.briarproject.api.TransportId;
import org.briarproject.api.TransportProperties; import org.briarproject.api.TransportProperties;
import org.briarproject.api.crypto.SecretKey; import org.briarproject.api.crypto.SecretKey;
import org.briarproject.api.db.DbException; import org.briarproject.api.db.DbException;
import org.briarproject.api.db.MessageHeader; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.GroupId;
import org.briarproject.api.messaging.GroupId; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.MessageHeader;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.transport.IncomingKeys; import org.briarproject.api.transport.IncomingKeys;
import org.briarproject.api.transport.OutgoingKeys; import org.briarproject.api.transport.OutgoingKeys;
import org.briarproject.api.transport.TransportKeys; import org.briarproject.api.transport.TransportKeys;
@@ -43,8 +43,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.api.db.MessageHeader.State.STORED; import static org.briarproject.api.sync.MessageHeader.State.STORED;
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH; import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;

View File

@@ -1,4 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@@ -17,18 +17,18 @@ import org.briarproject.api.crypto.CryptoComponent;
import org.briarproject.api.crypto.KeyPair; import org.briarproject.api.crypto.KeyPair;
import org.briarproject.api.crypto.PrivateKey; import org.briarproject.api.crypto.PrivateKey;
import org.briarproject.api.crypto.Signature; import org.briarproject.api.crypto.Signature;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupFactory; import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageFactory; import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.Offer; import org.briarproject.api.sync.Offer;
import org.briarproject.api.messaging.PacketWriter; import org.briarproject.api.sync.PacketWriter;
import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.sync.PacketWriterFactory;
import org.briarproject.api.messaging.Request; import org.briarproject.api.sync.Request;
import org.briarproject.api.messaging.SubscriptionUpdate; import org.briarproject.api.sync.SubscriptionUpdate;
import org.briarproject.api.messaging.TransportUpdate; import org.briarproject.api.sync.TransportUpdate;
import org.briarproject.crypto.CryptoModule; import org.briarproject.crypto.CryptoModule;
import org.briarproject.data.DataModule; import org.briarproject.data.DataModule;
import org.briarproject.db.DatabaseModule; import org.briarproject.db.DatabaseModule;
@@ -46,11 +46,11 @@ import static org.briarproject.api.AuthorConstants.MAX_SIGNATURE_LENGTH;
import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT; import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTIES_PER_TRANSPORT;
import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTY_LENGTH; import static org.briarproject.api.TransportPropertyConstants.MAX_PROPERTY_LENGTH;
import static org.briarproject.api.TransportPropertyConstants.MAX_TRANSPORT_ID_LENGTH; import static org.briarproject.api.TransportPropertyConstants.MAX_TRANSPORT_ID_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_BODY_LENGTH; import static org.briarproject.api.sync.MessagingConstants.MAX_BODY_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_CONTENT_TYPE_LENGTH; import static org.briarproject.api.sync.MessagingConstants.MAX_CONTENT_TYPE_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_GROUP_NAME_LENGTH; import static org.briarproject.api.sync.MessagingConstants.MAX_GROUP_NAME_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH; import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_SUBSCRIPTIONS; import static org.briarproject.api.sync.MessagingConstants.MAX_SUBSCRIPTIONS;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class ConstantsTest extends BriarTestCase { public class ConstantsTest extends BriarTestCase {
@@ -65,7 +65,7 @@ public class ConstantsTest extends BriarTestCase {
Injector i = Guice.createInjector(new TestDatabaseModule(), Injector i = Guice.createInjector(new TestDatabaseModule(),
new TestLifecycleModule(), new TestSystemModule(), new TestLifecycleModule(), new TestSystemModule(),
new CryptoModule(), new DatabaseModule(), new EventModule(), new CryptoModule(), new DatabaseModule(), new EventModule(),
new MessagingModule(), new DataModule()); new org.briarproject.sync.MessagingModule(), new DataModule());
crypto = i.getInstance(CryptoComponent.class); crypto = i.getInstance(CryptoComponent.class);
groupFactory = i.getInstance(GroupFactory.class); groupFactory = i.getInstance(GroupFactory.class);
authorFactory = i.getInstance(AuthorFactory.class); authorFactory = i.getInstance(AuthorFactory.class);

View File

@@ -1,4 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import org.briarproject.BriarTestCase; import org.briarproject.BriarTestCase;
import org.briarproject.api.FormatException; import org.briarproject.api.FormatException;
@@ -23,7 +23,8 @@ public class ConsumersTest extends BriarTestCase {
messageDigest.update(data); messageDigest.update(data);
byte[] dig = messageDigest.digest(); byte[] dig = messageDigest.digest();
// Check that feeding a DigestingConsumer generates the same digest // Check that feeding a DigestingConsumer generates the same digest
DigestingConsumer dc = new DigestingConsumer(messageDigest); org.briarproject.sync.DigestingConsumer
dc = new org.briarproject.sync.DigestingConsumer(messageDigest);
dc.write(data[0]); dc.write(data[0]);
dc.write(data, 1, data.length - 2); dc.write(data, 1, data.length - 2);
dc.write(data[data.length - 1]); dc.write(data[data.length - 1]);
@@ -34,7 +35,8 @@ public class ConsumersTest extends BriarTestCase {
@Test @Test
public void testCountingConsumer() throws Exception { public void testCountingConsumer() throws Exception {
byte[] data = new byte[1234]; byte[] data = new byte[1234];
CountingConsumer cc = new CountingConsumer(data.length); org.briarproject.sync.CountingConsumer
cc = new org.briarproject.sync.CountingConsumer(data.length);
cc.write(data[0]); cc.write(data[0]);
cc.write(data, 1, data.length - 2); cc.write(data, 1, data.length - 2);
cc.write(data[data.length - 1]); cc.write(data[data.length - 1]);
@@ -42,7 +44,9 @@ public class ConsumersTest extends BriarTestCase {
try { try {
cc.write((byte) 0); cc.write((byte) 0);
fail(); fail();
} catch (FormatException expected) {} } catch (FormatException expected) {
// Expected
}
} }
@Test @Test
@@ -50,7 +54,8 @@ public class ConsumersTest extends BriarTestCase {
byte[] data = new byte[1234]; byte[] data = new byte[1234];
new Random().nextBytes(data); new Random().nextBytes(data);
// Check that a CopyingConsumer creates a faithful copy // Check that a CopyingConsumer creates a faithful copy
CopyingConsumer cc = new CopyingConsumer(); org.briarproject.sync.CopyingConsumer
cc = new org.briarproject.sync.CopyingConsumer();
cc.write(data[0]); cc.write(data[0]);
cc.write(data, 1, data.length - 2); cc.write(data, 1, data.length - 2);
cc.write(data[data.length - 1]); cc.write(data[data.length - 1]);

View File

@@ -1,4 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@@ -18,11 +18,11 @@ import java.io.ByteArrayOutputStream;
import static org.briarproject.api.data.DataConstants.LIST_END_LENGTH; import static org.briarproject.api.data.DataConstants.LIST_END_LENGTH;
import static org.briarproject.api.data.DataConstants.UNIQUE_ID_LENGTH; import static org.briarproject.api.data.DataConstants.UNIQUE_ID_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.HEADER_LENGTH; import static org.briarproject.api.sync.MessagingConstants.HEADER_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.MAX_PAYLOAD_LENGTH; import static org.briarproject.api.sync.MessagingConstants.MAX_PAYLOAD_LENGTH;
import static org.briarproject.api.messaging.PacketTypes.ACK; import static org.briarproject.api.sync.PacketTypes.ACK;
import static org.briarproject.api.messaging.PacketTypes.OFFER; import static org.briarproject.api.sync.PacketTypes.OFFER;
import static org.briarproject.api.messaging.PacketTypes.REQUEST; import static org.briarproject.api.sync.PacketTypes.REQUEST;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@@ -43,19 +43,23 @@ public class PacketReaderImplTest extends BriarTestCase {
public void testFormatExceptionIfAckIsTooLarge() throws Exception { public void testFormatExceptionIfAckIsTooLarge() throws Exception {
byte[] b = createAck(true); byte[] b = createAck(true);
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
try { try {
reader.readAck(); reader.readAck();
fail(); fail();
} catch (FormatException expected) {} } catch (FormatException expected) {
// Expected
}
} }
@Test @Test
public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception { public void testNoFormatExceptionIfAckIsMaximumSize() throws Exception {
byte[] b = createAck(false); byte[] b = createAck(false);
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
reader.readAck(); reader.readAck();
} }
@@ -64,31 +68,38 @@ public class PacketReaderImplTest extends BriarTestCase {
public void testEmptyAck() throws Exception { public void testEmptyAck() throws Exception {
byte[] b = createEmptyAck(); byte[] b = createEmptyAck();
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
try { try {
reader.readAck(); reader.readAck();
fail(); fail();
} catch (FormatException expected) {} } catch (FormatException expected) {
// Expected
}
} }
@Test @Test
public void testFormatExceptionIfOfferIsTooLarge() throws Exception { public void testFormatExceptionIfOfferIsTooLarge() throws Exception {
byte[] b = createOffer(true); byte[] b = createOffer(true);
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
try { try {
reader.readOffer(); reader.readOffer();
fail(); fail();
} catch (FormatException expected) {} } catch (FormatException expected) {
// Expected
}
} }
@Test @Test
public void testNoFormatExceptionIfOfferIsMaximumSize() throws Exception { public void testNoFormatExceptionIfOfferIsMaximumSize() throws Exception {
byte[] b = createOffer(false); byte[] b = createOffer(false);
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
reader.readOffer(); reader.readOffer();
} }
@@ -97,31 +108,38 @@ public class PacketReaderImplTest extends BriarTestCase {
public void testEmptyOffer() throws Exception { public void testEmptyOffer() throws Exception {
byte[] b = createEmptyOffer(); byte[] b = createEmptyOffer();
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
try { try {
reader.readOffer(); reader.readOffer();
fail(); fail();
} catch (FormatException expected) {} } catch (FormatException expected) {
// Expected
}
} }
@Test @Test
public void testFormatExceptionIfRequestIsTooLarge() throws Exception { public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
byte[] b = createRequest(true); byte[] b = createRequest(true);
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
try { try {
reader.readRequest(); reader.readRequest();
fail(); fail();
} catch (FormatException expected) {} } catch (FormatException expected) {
// Expected
}
} }
@Test @Test
public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception { public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception {
byte[] b = createRequest(false); byte[] b = createRequest(false);
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
reader.readRequest(); reader.readRequest();
} }
@@ -130,12 +148,15 @@ public class PacketReaderImplTest extends BriarTestCase {
public void testEmptyRequest() throws Exception { public void testEmptyRequest() throws Exception {
byte[] b = createEmptyRequest(); byte[] b = createEmptyRequest();
ByteArrayInputStream in = new ByteArrayInputStream(b); ByteArrayInputStream in = new ByteArrayInputStream(b);
PacketReaderImpl reader = new PacketReaderImpl(readerFactory, null, org.briarproject.sync.PacketReaderImpl
reader = new org.briarproject.sync.PacketReaderImpl(readerFactory, null,
null, in); null, in);
try { try {
reader.readRequest(); reader.readRequest();
fail(); fail();
} catch (FormatException expected) {} } catch (FormatException expected) {
// Expected
}
} }
private byte[] createAck(boolean tooBig) throws Exception { private byte[] createAck(boolean tooBig) throws Exception {

View File

@@ -1,4 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@@ -20,16 +20,16 @@ import org.briarproject.api.event.Event;
import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventBus;
import org.briarproject.api.event.EventListener; import org.briarproject.api.event.EventListener;
import org.briarproject.api.event.MessageAddedEvent; import org.briarproject.api.event.MessageAddedEvent;
import org.briarproject.api.messaging.Group; import org.briarproject.api.sync.Group;
import org.briarproject.api.messaging.GroupFactory; import org.briarproject.api.sync.GroupFactory;
import org.briarproject.api.messaging.Message; import org.briarproject.api.sync.Message;
import org.briarproject.api.messaging.MessageFactory; import org.briarproject.api.sync.MessageFactory;
import org.briarproject.api.messaging.MessageVerifier; import org.briarproject.api.sync.MessageVerifier;
import org.briarproject.api.messaging.MessagingSession; import org.briarproject.api.sync.MessagingSession;
import org.briarproject.api.messaging.PacketReader; import org.briarproject.api.sync.PacketReader;
import org.briarproject.api.messaging.PacketReaderFactory; import org.briarproject.api.sync.PacketReaderFactory;
import org.briarproject.api.messaging.PacketWriter; import org.briarproject.api.sync.PacketWriter;
import org.briarproject.api.messaging.PacketWriterFactory; import org.briarproject.api.sync.PacketWriterFactory;
import org.briarproject.api.transport.KeyManager; import org.briarproject.api.transport.KeyManager;
import org.briarproject.api.transport.StreamContext; import org.briarproject.api.transport.StreamContext;
import org.briarproject.api.transport.StreamReaderFactory; import org.briarproject.api.transport.StreamReaderFactory;
@@ -53,7 +53,7 @@ import java.io.OutputStream;
import java.util.Collections; import java.util.Collections;
import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH; import static org.briarproject.api.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
import static org.briarproject.api.messaging.MessagingConstants.GROUP_SALT_LENGTH; import static org.briarproject.api.sync.MessagingConstants.GROUP_SALT_LENGTH;
import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE; import static org.briarproject.api.transport.TransportConstants.MAX_CLOCK_DIFFERENCE;
import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH; import static org.briarproject.api.transport.TransportConstants.TAG_LENGTH;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -87,7 +87,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
return Guice.createInjector(new TestDatabaseModule(dir), return Guice.createInjector(new TestDatabaseModule(dir),
new TestLifecycleModule(), new TestSystemModule(), new TestLifecycleModule(), new TestSystemModule(),
new CryptoModule(), new DatabaseModule(), new EventModule(), new CryptoModule(), new DatabaseModule(), new EventModule(),
new MessagingModule(), new DataModule(), new org.briarproject.sync.MessagingModule(), new DataModule(),
new TransportModule()); new TransportModule());
} }
@@ -149,7 +149,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
alice.getInstance(PacketWriterFactory.class); alice.getInstance(PacketWriterFactory.class);
PacketWriter packetWriter = packetWriterFactory.createPacketWriter( PacketWriter packetWriter = packetWriterFactory.createPacketWriter(
streamWriter); streamWriter);
MessagingSession session = new SimplexOutgoingSession(db, MessagingSession session = new org.briarproject.sync.SimplexOutgoingSession(db,
new ImmediateExecutor(), eventBus, contactId, transportId, new ImmediateExecutor(), eventBus, contactId, transportId,
MAX_LATENCY, packetWriter); MAX_LATENCY, packetWriter);
// Write whatever needs to be written // Write whatever needs to be written
@@ -216,7 +216,7 @@ public class SimplexMessagingIntegrationTest extends BriarTestCase {
bob.getInstance(PacketReaderFactory.class); bob.getInstance(PacketReaderFactory.class);
PacketReader packetReader = packetReaderFactory.createPacketReader( PacketReader packetReader = packetReaderFactory.createPacketReader(
streamReader); streamReader);
MessagingSession session = new IncomingSession(db, MessagingSession session = new org.briarproject.sync.IncomingSession(db,
new ImmediateExecutor(), new ImmediateExecutor(), eventBus, new ImmediateExecutor(), new ImmediateExecutor(), eventBus,
messageVerifier, contactId, transportId, packetReader); messageVerifier, contactId, transportId, packetReader);
// No messages should have been added yet // No messages should have been added yet

View File

@@ -1,4 +1,4 @@
package org.briarproject.messaging; package org.briarproject.sync;
import org.briarproject.BriarTestCase; import org.briarproject.BriarTestCase;
import org.briarproject.TestUtils; import org.briarproject.TestUtils;
@@ -6,15 +6,16 @@ import org.briarproject.api.ContactId;
import org.briarproject.api.TransportId; import org.briarproject.api.TransportId;
import org.briarproject.api.db.DatabaseComponent; import org.briarproject.api.db.DatabaseComponent;
import org.briarproject.api.event.EventBus; import org.briarproject.api.event.EventBus;
import org.briarproject.api.messaging.Ack; import org.briarproject.api.sync.Ack;
import org.briarproject.api.messaging.MessageId; import org.briarproject.api.sync.MessageId;
import org.briarproject.api.messaging.PacketWriter; import org.briarproject.api.sync.PacketWriter;
import org.briarproject.plugins.ImmediateExecutor; import org.briarproject.plugins.ImmediateExecutor;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.jmock.Mockery; import org.jmock.Mockery;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
public class SimplexOutgoingSessionTest extends BriarTestCase { public class SimplexOutgoingSessionTest extends BriarTestCase {
@@ -45,7 +46,8 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
@Test @Test
public void testNothingToSend() throws Exception { public void testNothingToSend() throws Exception {
final SimplexOutgoingSession session = new SimplexOutgoingSession(db, final org.briarproject.sync.SimplexOutgoingSession
session = new org.briarproject.sync.SimplexOutgoingSession(db,
dbExecutor, eventBus, contactId, transportId, maxLatency, dbExecutor, eventBus, contactId, transportId, maxLatency,
packetWriter); packetWriter);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
@@ -89,9 +91,10 @@ public class SimplexOutgoingSessionTest extends BriarTestCase {
@Test @Test
public void testSomethingToSend() throws Exception { public void testSomethingToSend() throws Exception {
final Ack ack = new Ack(Arrays.asList(messageId)); final Ack ack = new Ack(Collections.singletonList(messageId));
final byte[] raw = new byte[1234]; final byte[] raw = new byte[1234];
final SimplexOutgoingSession session = new SimplexOutgoingSession(db, final org.briarproject.sync.SimplexOutgoingSession
session = new org.briarproject.sync.SimplexOutgoingSession(db,
dbExecutor, eventBus, contactId, transportId, maxLatency, dbExecutor, eventBus, contactId, transportId, maxLatency,
packetWriter); packetWriter);
context.checking(new Expectations() {{ context.checking(new Expectations() {{