Split package messages into header and body, move BufferUtils to util.

This commit is contained in:
Felix Ableitner 2015-04-16 09:25:39 +02:00
parent 5c102581ce
commit 85a8b71fe9
37 changed files with 80 additions and 64 deletions

View file

@ -1,7 +1,6 @@
package com.nutomic.ensichat.protocol package com.nutomic.ensichat.protocol
import android.test.AndroidTestCase import android.test.AndroidTestCase
import com.nutomic.ensichat.protocol.messages.MessageTest
import junit.framework.Assert._ import junit.framework.Assert._
class CryptoTest extends AndroidTestCase { class CryptoTest extends AndroidTestCase {

View file

@ -1,12 +1,13 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol
import java.io.ByteArrayInputStream import java.io.ByteArrayInputStream
import java.util.GregorianCalendar import java.util.GregorianCalendar
import android.test.AndroidTestCase import android.test.AndroidTestCase
import com.nutomic.ensichat.protocol.messages.ContentHeaderTest._ import com.nutomic.ensichat.protocol.body.{ConnectionInfo, ConnectionInfoTest, Text}
import com.nutomic.ensichat.protocol.messages.MessageTest._ import com.nutomic.ensichat.protocol.header.ContentHeaderTest._
import com.nutomic.ensichat.protocol.{AddressTest, Crypto} import com.nutomic.ensichat.protocol.MessageTest._
import com.nutomic.ensichat.protocol.header.MessageHeader
import junit.framework.Assert._ import junit.framework.Assert._
import scala.collection.immutable.TreeSet import scala.collection.immutable.TreeSet

View file

@ -1,7 +1,8 @@
package com.nutomic.ensichat.protocol package com.nutomic.ensichat.protocol
import android.test.AndroidTestCase import android.test.AndroidTestCase
import com.nutomic.ensichat.protocol.messages._ import com.nutomic.ensichat.protocol.body.UserName
import com.nutomic.ensichat.protocol.header.ContentHeader
import junit.framework.Assert._ import junit.framework.Assert._
class RouterTest extends AndroidTestCase { class RouterTest extends AndroidTestCase {

View file

@ -1,4 +1,4 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import android.content.Context import android.content.Context
import android.test.AndroidTestCase import android.test.AndroidTestCase
@ -25,4 +25,4 @@ class ConnectionInfoTest extends AndroidTestCase {
Assert.assertEquals(ci.key, body.asInstanceOf[ConnectionInfo].key) Assert.assertEquals(ci.key, body.asInstanceOf[ConnectionInfo].key)
} }
} }

View file

@ -1,4 +1,4 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import android.test.AndroidTestCase import android.test.AndroidTestCase
import junit.framework.Assert._ import junit.framework.Assert._

View file

@ -1,4 +1,4 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import android.test.AndroidTestCase import android.test.AndroidTestCase
import junit.framework.Assert import junit.framework.Assert
@ -12,4 +12,4 @@ class UserNameTest extends AndroidTestCase {
Assert.assertEquals(name, body.asInstanceOf[UserName]) Assert.assertEquals(name, body.asInstanceOf[UserName])
} }
} }

View file

@ -1,6 +1,7 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.header
import android.test.AndroidTestCase import android.test.AndroidTestCase
import com.nutomic.ensichat.protocol.body.Text
import com.nutomic.ensichat.protocol.{Address, AddressTest} import com.nutomic.ensichat.protocol.{Address, AddressTest}
import junit.framework.Assert._ import junit.framework.Assert._

View file

@ -1,7 +1,7 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.header
import android.test.AndroidTestCase import android.test.AndroidTestCase
import com.nutomic.ensichat.protocol.messages.MessageHeaderTest._ import com.nutomic.ensichat.protocol.header.MessageHeaderTest._
import com.nutomic.ensichat.protocol.{Address, AddressTest} import com.nutomic.ensichat.protocol.{Address, AddressTest}
import junit.framework.Assert._ import junit.framework.Assert._

View file

@ -2,8 +2,9 @@ package com.nutomic.ensichat.util
import android.content.Context import android.content.Context
import android.test.AndroidTestCase import android.test.AndroidTestCase
import com.nutomic.ensichat.protocol.messages._ import com.nutomic.ensichat.protocol.body.{RequestAddContact, ResultAddContact}
import com.nutomic.ensichat.protocol.{Address, Crypto, UserTest} import com.nutomic.ensichat.protocol.header.ContentHeader
import com.nutomic.ensichat.protocol.{Address, Crypto, Message, UserTest}
import junit.framework.Assert._ import junit.framework.Assert._
class AddContactsHandlerTest extends AndroidTestCase { class AddContactsHandlerTest extends AndroidTestCase {

View file

@ -6,10 +6,12 @@ import android.content.Context
import android.database.DatabaseErrorHandler import android.database.DatabaseErrorHandler
import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteDatabase
import android.test.{AndroidTestCase, mock} import android.test.{AndroidTestCase, mock}
import com.nutomic.ensichat.protocol.UserTest import com.nutomic.ensichat.protocol.{MessageTest, UserTest}
import com.nutomic.ensichat.protocol.messages.ContentHeaderTest._ import com.nutomic.ensichat.protocol.body.CryptoData
import com.nutomic.ensichat.protocol.messages.MessageTest._ import com.nutomic.ensichat.protocol.header.ContentHeaderTest
import com.nutomic.ensichat.protocol.messages.{ContentHeader, CryptoData} import com.nutomic.ensichat.protocol.header.ContentHeader
import ContentHeaderTest._
import MessageTest._
import com.nutomic.ensichat.util.Database.OnContactsUpdatedListener import com.nutomic.ensichat.util.Database.OnContactsUpdatedListener
import junit.framework.Assert._ import junit.framework.Assert._

View file

@ -8,7 +8,7 @@ import android.widget.AdapterView.OnItemClickListener
import android.widget._ import android.widget._
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.protocol.ChatService import com.nutomic.ensichat.protocol.ChatService
import com.nutomic.ensichat.protocol.messages.RequestAddContact import com.nutomic.ensichat.protocol.body.RequestAddContact
import com.nutomic.ensichat.util.Database.OnContactsUpdatedListener import com.nutomic.ensichat.util.Database.OnContactsUpdatedListener
import com.nutomic.ensichat.util.{Database, UsersAdapter} import com.nutomic.ensichat.util.{Database, UsersAdapter}

View file

@ -7,7 +7,7 @@ import android.os.Bundle
import android.view.{ContextThemeWrapper, LayoutInflater} import android.view.{ContextThemeWrapper, LayoutInflater}
import android.widget.{ImageView, TextView} import android.widget.{ImageView, TextView}
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.protocol.messages.ResultAddContact import com.nutomic.ensichat.protocol.body.ResultAddContact
import com.nutomic.ensichat.protocol.{Address, Crypto} import com.nutomic.ensichat.protocol.{Address, Crypto}
import com.nutomic.ensichat.util.IdenticonGenerator import com.nutomic.ensichat.util.IdenticonGenerator

View file

@ -12,7 +12,7 @@ import com.nutomic.ensichat.R
import com.nutomic.ensichat.fragments.SettingsFragment import com.nutomic.ensichat.fragments.SettingsFragment
import com.nutomic.ensichat.protocol.ChatService.InterfaceHandler import com.nutomic.ensichat.protocol.ChatService.InterfaceHandler
import com.nutomic.ensichat.protocol._ import com.nutomic.ensichat.protocol._
import com.nutomic.ensichat.protocol.messages.{ConnectionInfo, Message} import com.nutomic.ensichat.protocol.body.ConnectionInfo
import scala.collection.immutable.HashMap import scala.collection.immutable.HashMap

View file

@ -5,8 +5,9 @@ import java.io._
import android.bluetooth.BluetoothSocket import android.bluetooth.BluetoothSocket
import android.util.Log import android.util.Log
import com.nutomic.ensichat.protocol._ import com.nutomic.ensichat.protocol._
import com.nutomic.ensichat.protocol.messages.Message.ReadMessageException import com.nutomic.ensichat.protocol.body.ConnectionInfo
import com.nutomic.ensichat.protocol.messages.{ConnectionInfo, Message, MessageHeader} import com.nutomic.ensichat.protocol.header.MessageHeader
import Message.ReadMessageException
/** /**
* Transfers data between connnected devices. * Transfers data between connnected devices.

View file

@ -10,8 +10,8 @@ import android.widget._
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.activities.EnsiChatActivity import com.nutomic.ensichat.activities.EnsiChatActivity
import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener
import com.nutomic.ensichat.protocol.messages.{Message, Text} import com.nutomic.ensichat.protocol.body.Text
import com.nutomic.ensichat.protocol.{Address, ChatService} import com.nutomic.ensichat.protocol.{Message, Address, ChatService}
import com.nutomic.ensichat.util.{Database, MessagesAdapter} import com.nutomic.ensichat.util.{Database, MessagesAdapter}
/** /**

View file

@ -6,7 +6,7 @@ import android.preference.{Preference, PreferenceFragment, PreferenceManager}
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.activities.EnsiChatActivity import com.nutomic.ensichat.activities.EnsiChatActivity
import com.nutomic.ensichat.fragments.SettingsFragment._ import com.nutomic.ensichat.fragments.SettingsFragment._
import com.nutomic.ensichat.protocol.messages.UserName import com.nutomic.ensichat.protocol.body.UserName
import com.nutomic.ensichat.util.Database import com.nutomic.ensichat.util.Database
object SettingsFragment { object SettingsFragment {

View file

@ -10,7 +10,8 @@ import com.nutomic.ensichat.R
import com.nutomic.ensichat.bluetooth.BluetoothInterface import com.nutomic.ensichat.bluetooth.BluetoothInterface
import com.nutomic.ensichat.fragments.SettingsFragment import com.nutomic.ensichat.fragments.SettingsFragment
import com.nutomic.ensichat.protocol.ChatService.{OnConnectionsChangedListener, OnMessageReceivedListener} import com.nutomic.ensichat.protocol.ChatService.{OnConnectionsChangedListener, OnMessageReceivedListener}
import com.nutomic.ensichat.protocol.messages._ import com.nutomic.ensichat.protocol.body.{UserName, MessageBody, ConnectionInfo}
import com.nutomic.ensichat.protocol.header.ContentHeader
import com.nutomic.ensichat.util.{AddContactsHandler, Database, NotificationHandler} import com.nutomic.ensichat.util.{AddContactsHandler, Database, NotificationHandler}
import scala.collection.mutable import scala.collection.mutable

View file

@ -10,7 +10,8 @@ import android.content.Context
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.util.Log import android.util.Log
import com.nutomic.ensichat.protocol.Crypto._ import com.nutomic.ensichat.protocol.Crypto._
import com.nutomic.ensichat.protocol.messages._ import com.nutomic.ensichat.protocol.body._
import com.nutomic.ensichat.protocol.header.ContentHeader
import com.nutomic.ensichat.util.PRNGFixes import com.nutomic.ensichat.util.PRNGFixes
object Crypto { object Crypto {

View file

@ -1,8 +1,11 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol
import java.io.InputStream import java.io.InputStream
import java.security.spec.InvalidKeySpecException import java.security.spec.InvalidKeySpecException
import com.nutomic.ensichat.protocol.body._
import com.nutomic.ensichat.protocol.header.{AbstractHeader, ContentHeader, MessageHeader}
object Message { object Message {
/** /**

View file

@ -1,6 +1,6 @@
package com.nutomic.ensichat.protocol package com.nutomic.ensichat.protocol
import com.nutomic.ensichat.protocol.messages.{ContentHeader, Message} import com.nutomic.ensichat.protocol.header.ContentHeader
/** /**
* Forwards messages to all connected devices. * Forwards messages to all connected devices.

View file

@ -2,7 +2,7 @@ package com.nutomic.ensichat.protocol
import android.content.Context import android.content.Context
import android.preference.PreferenceManager import android.preference.PreferenceManager
import com.nutomic.ensichat.protocol.messages.ContentHeader import com.nutomic.ensichat.protocol.header.ContentHeader
/** /**
* Generates sequence numbers acorrding to protocol, which are stored persistently. * Generates sequence numbers acorrding to protocol, which are stored persistently.

View file

@ -1,10 +1,11 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.security.spec.X509EncodedKeySpec import java.security.spec.X509EncodedKeySpec
import java.security.{KeyFactory, PublicKey} import java.security.{KeyFactory, PublicKey}
import com.nutomic.ensichat.protocol.{BufferUtils, Crypto} import com.nutomic.ensichat.protocol.Crypto
import com.nutomic.ensichat.util.BufferUtils
object ConnectionInfo { object ConnectionInfo {

View file

@ -1,9 +1,9 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.util import java.util
import com.nutomic.ensichat.protocol.BufferUtils import com.nutomic.ensichat.util.BufferUtils
object CryptoData { object CryptoData {

View file

@ -1,4 +1,4 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
/** /**
* Represents the data in an encrypted message body. * Represents the data in an encrypted message body.

View file

@ -1,4 +1,4 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
/** /**
* Holds the actual message content. * Holds the actual message content.

View file

@ -1,4 +1,4 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import java.nio.ByteBuffer import java.nio.ByteBuffer

View file

@ -1,8 +1,8 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import java.nio.ByteBuffer import java.nio.ByteBuffer
import com.nutomic.ensichat.protocol.BufferUtils import com.nutomic.ensichat.util.BufferUtils
object ResultAddContact { object ResultAddContact {

View file

@ -1,9 +1,9 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.util.Date import java.util.Date
import com.nutomic.ensichat.protocol.Message
import com.nutomic.ensichat.protocol.BufferUtils import com.nutomic.ensichat.util.BufferUtils
object Text { object Text {

View file

@ -1,8 +1,8 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.body
import java.nio.ByteBuffer import java.nio.ByteBuffer
import com.nutomic.ensichat.protocol.Message
import com.nutomic.ensichat.protocol.BufferUtils import com.nutomic.ensichat.util.BufferUtils
object UserName { object UserName {

View file

@ -1,8 +1,9 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.header
import java.nio.ByteBuffer import java.nio.ByteBuffer
import com.nutomic.ensichat.protocol.{Address, BufferUtils} import com.nutomic.ensichat.protocol.Address
import com.nutomic.ensichat.util.BufferUtils
object AbstractHeader { object AbstractHeader {
@ -10,7 +11,7 @@ object AbstractHeader {
val Version = 0 val Version = 0
private[messages] val Length = 10 + 2 * Address.Length private[header] val Length = 10 + 2 * Address.Length
} }

View file

@ -1,8 +1,9 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.header
import java.nio.ByteBuffer import java.nio.ByteBuffer
import com.nutomic.ensichat.protocol.{Address, BufferUtils} import com.nutomic.ensichat.protocol.Address
import com.nutomic.ensichat.util.BufferUtils
object ContentHeader { object ContentHeader {

View file

@ -1,9 +1,10 @@
package com.nutomic.ensichat.protocol.messages package com.nutomic.ensichat.protocol.header
import java.nio.ByteBuffer import java.nio.ByteBuffer
import com.nutomic.ensichat.protocol.messages.Message.ParseMessageException import com.nutomic.ensichat.protocol.{Message, Address}
import com.nutomic.ensichat.protocol.{Address, BufferUtils} import Message.ParseMessageException
import com.nutomic.ensichat.util.BufferUtils
object MessageHeader { object MessageHeader {

View file

@ -7,8 +7,8 @@ import android.widget.Toast
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.activities.ConfirmAddContactActivity import com.nutomic.ensichat.activities.ConfirmAddContactActivity
import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener
import com.nutomic.ensichat.protocol.messages.{Message, RequestAddContact, ResultAddContact} import com.nutomic.ensichat.protocol.body.{ResultAddContact, RequestAddContact}
import com.nutomic.ensichat.protocol.{Address, User} import com.nutomic.ensichat.protocol.{Message, Address, User}
/** /**
* Handles [[RequestAddContact]] and [[ResultAddContact]] messages, adds new contacts. * Handles [[RequestAddContact]] and [[ResultAddContact]] messages, adds new contacts.

View file

@ -1,4 +1,4 @@
package com.nutomic.ensichat.protocol package com.nutomic.ensichat.util
import java.nio.ByteBuffer import java.nio.ByteBuffer

View file

@ -6,7 +6,8 @@ import android.content.{ContentValues, Context}
import android.database.sqlite.{SQLiteDatabase, SQLiteOpenHelper} import android.database.sqlite.{SQLiteDatabase, SQLiteOpenHelper}
import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener
import com.nutomic.ensichat.protocol._ import com.nutomic.ensichat.protocol._
import com.nutomic.ensichat.protocol.messages._ import com.nutomic.ensichat.protocol.body.{Text, ResultAddContact, RequestAddContact}
import com.nutomic.ensichat.protocol.header.ContentHeader
import com.nutomic.ensichat.util.Database.OnContactsUpdatedListener import com.nutomic.ensichat.util.Database.OnContactsUpdatedListener
import scala.collection.immutable.TreeSet import scala.collection.immutable.TreeSet

View file

@ -4,8 +4,8 @@ import android.content.Context
import android.view.{Gravity, View, ViewGroup} import android.view.{Gravity, View, ViewGroup}
import android.widget.{ArrayAdapter, RelativeLayout, TextView} import android.widget.{ArrayAdapter, RelativeLayout, TextView}
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.protocol.Address import com.nutomic.ensichat.protocol.{Message, Address}
import com.nutomic.ensichat.protocol.messages.{Message, Text} import com.nutomic.ensichat.protocol.body.Text
/** /**
* Displays [[Message]]s in ListView. * Displays [[Message]]s in ListView.

View file

@ -5,8 +5,8 @@ import android.content.{Context, Intent}
import com.nutomic.ensichat.R import com.nutomic.ensichat.R
import com.nutomic.ensichat.activities.MainActivity import com.nutomic.ensichat.activities.MainActivity
import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener import com.nutomic.ensichat.protocol.ChatService.OnMessageReceivedListener
import com.nutomic.ensichat.protocol.Crypto import com.nutomic.ensichat.protocol.{Message, Crypto}
import com.nutomic.ensichat.protocol.messages.{Message, Text} import com.nutomic.ensichat.protocol.body.Text
/** /**
* Displays notifications for new messages. * Displays notifications for new messages.