├── .gitattributes ├── projects ├── build-basic │ ├── project │ │ ├── src │ │ ├── depends.sbt │ │ ├── build.properties │ │ └── plugins.sbt │ ├── src │ │ ├── test │ │ │ └── scala │ │ │ │ ├── TravisBenchSuite.scala │ │ │ │ └── org │ │ │ │ └── scalastyle │ │ │ │ └── scalariform │ │ │ │ └── tox4j │ │ │ │ ├── ForBraceCheckerTest.scala │ │ │ │ └── RedundantValCheckerTest.scala │ │ └── main │ │ │ └── scala │ │ │ ├── sbt │ │ │ └── tox4j │ │ │ │ ├── OptionalPlugin.scala │ │ │ │ ├── lint │ │ │ │ ├── Xlint.scala │ │ │ │ ├── Scalastyle.scala │ │ │ │ └── Findbugs.scala │ │ │ │ ├── CodeFormat.scala │ │ │ │ ├── logic │ │ │ │ └── jni │ │ │ │ │ └── BuildTool.scala │ │ │ │ └── MakeScripts.scala │ │ │ └── org │ │ │ └── scalastyle │ │ │ └── scalariform │ │ │ ├── AstChecker.scala │ │ │ └── tox4j │ │ │ └── ForBraceChecker.scala │ ├── build.sbt │ └── depends.sbt ├── build-extra │ ├── project │ │ ├── src │ │ ├── depends.sbt │ │ ├── build.properties │ │ └── plugins.sbt │ ├── src │ │ ├── test │ │ │ └── scala │ │ │ │ └── TravisBenchSuite.scala │ │ └── main │ │ │ └── scala │ │ │ └── sbt │ │ │ └── tox4j │ │ │ ├── lint │ │ │ └── Foursquare.scala │ │ │ └── Coverage.scala │ ├── build.sbt │ └── depends.sbt ├── tox4j │ ├── android │ │ ├── .gitignore │ │ ├── local.i686-linux-android.sbt │ │ ├── local.arm-linux-androideabi.sbt │ │ ├── toxcore.patch │ │ ├── protobuf.patch │ │ └── libvpx.patch │ ├── project │ │ ├── .gitignore │ │ ├── build.properties │ │ └── plugins.sbt │ ├── src │ │ ├── main │ │ │ ├── ocaml │ │ │ │ ├── core │ │ │ │ │ ├── _tags │ │ │ │ │ ├── protocol.ml │ │ │ │ │ ├── .merlin │ │ │ │ │ ├── publicKeyMap.ml │ │ │ │ │ ├── Makefile │ │ │ │ │ ├── Build.lsp │ │ │ │ │ ├── port.mli │ │ │ │ │ ├── nonce.ml │ │ │ │ │ ├── types.ml │ │ │ │ │ ├── port.ml │ │ │ │ │ ├── echoRequest.ml │ │ │ │ │ ├── echoResponse.ml │ │ │ │ │ ├── dhtPacket.ml │ │ │ │ │ ├── nodesRequest.ml │ │ │ │ │ ├── inetAddr.mli │ │ │ │ │ ├── nodesResponse.ml │ │ │ │ │ ├── node.ml │ │ │ │ │ ├── networkPacket.ml │ │ │ │ │ ├── dht.ml │ │ │ │ │ ├── crypto.ml │ │ │ │ │ ├── message.mli │ │ │ │ │ └── message.ml │ │ │ │ └── .gitignore │ │ │ ├── cpp │ │ │ │ ├── tox │ │ │ │ │ ├── core.cpp │ │ │ │ │ ├── av.cpp │ │ │ │ │ ├── core.h │ │ │ │ │ ├── generated │ │ │ │ │ │ └── av.h │ │ │ │ │ └── av.h │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── ToxAv │ │ │ │ │ ├── generated │ │ │ │ │ │ ├── impls.h │ │ │ │ │ │ └── natives.h │ │ │ │ │ ├── ToxAv.cpp │ │ │ │ │ ├── ToxAv.h │ │ │ │ │ └── debug.cpp │ │ │ │ ├── util │ │ │ │ │ ├── pp_cat.h │ │ │ │ │ ├── pp_attributes.h │ │ │ │ │ ├── unused.h │ │ │ │ │ ├── logging.cpp │ │ │ │ │ ├── exceptions.h │ │ │ │ │ └── wrap_void.h │ │ │ │ ├── ToxCrypto │ │ │ │ │ ├── ToxCrypto.h │ │ │ │ │ ├── hash.cpp │ │ │ │ │ ├── ToxCrypto.cpp │ │ │ │ │ └── generated │ │ │ │ │ │ ├── constants.h │ │ │ │ │ │ ├── errors.cpp │ │ │ │ │ │ └── natives.h │ │ │ │ ├── Tox4j.cpp │ │ │ │ ├── cpp14compat.h │ │ │ │ ├── tox4j │ │ │ │ │ └── Tox4j.h │ │ │ │ └── ToxCore │ │ │ │ │ ├── ToxCore.cpp │ │ │ │ │ ├── generated │ │ │ │ │ ├── impls.h │ │ │ │ │ └── constants.h │ │ │ │ │ ├── custom.cpp │ │ │ │ │ ├── interaction.cpp │ │ │ │ │ └── ToxCore.h │ │ │ └── java │ │ │ │ └── im │ │ │ │ └── tox │ │ │ │ ├── tox4j │ │ │ │ ├── av │ │ │ │ │ ├── exceptions │ │ │ │ │ │ ├── Makefile │ │ │ │ │ │ ├── ToxavNewException.java │ │ │ │ │ │ ├── ToxavCallControlException.java │ │ │ │ │ │ ├── ToxavBitRateSetException.java │ │ │ │ │ │ ├── ToxavAnswerException.java │ │ │ │ │ │ ├── ToxavCallException.java │ │ │ │ │ │ └── ToxavSendFrameException.java │ │ │ │ │ ├── callbacks │ │ │ │ │ │ ├── ToxAvEventAdapter.scala │ │ │ │ │ │ ├── ToxAvEventListener.scala │ │ │ │ │ │ ├── CallCallback.scala │ │ │ │ │ │ ├── BitRateStatusCallback.scala │ │ │ │ │ │ ├── AudioReceiveFrameCallback.scala │ │ │ │ │ │ └── CallStateCallback.scala │ │ │ │ │ └── enums │ │ │ │ │ │ ├── ToxavFriendCallState.java │ │ │ │ │ │ └── ToxavCallControl.java │ │ │ │ ├── core │ │ │ │ │ ├── exceptions │ │ │ │ │ │ ├── Makefile │ │ │ │ │ │ ├── ToxGetPortException.java │ │ │ │ │ │ ├── ToxSetTypingException.java │ │ │ │ │ │ ├── ToxFriendDeleteException.java │ │ │ │ │ │ ├── ToxFriendGetPublicKeyException.java │ │ │ │ │ │ ├── ToxSetInfoException.java │ │ │ │ │ │ ├── ToxFriendByPublicKeyException.java │ │ │ │ │ │ ├── ToxFileGetException.java │ │ │ │ │ │ ├── ToxBootstrapException.java │ │ │ │ │ │ ├── ToxFileSendException.java │ │ │ │ │ │ ├── ToxFileSeekException.java │ │ │ │ │ │ ├── ToxFriendSendMessageException.java │ │ │ │ │ │ ├── ToxFriendCustomPacketException.java │ │ │ │ │ │ └── ToxFileControlException.java │ │ │ │ │ ├── callbacks │ │ │ │ │ │ ├── ToxEventAdapter.scala │ │ │ │ │ │ ├── FriendNameCallback.scala │ │ │ │ │ │ ├── FriendTypingCallback.scala │ │ │ │ │ │ ├── FriendStatusMessageCallback.scala │ │ │ │ │ │ ├── FriendStatusCallback.scala │ │ │ │ │ │ ├── FriendLossyPacketCallback.scala │ │ │ │ │ │ ├── FriendLosslessPacketCallback.scala │ │ │ │ │ │ ├── FriendReadReceiptCallback.scala │ │ │ │ │ │ ├── FriendRequestCallback.scala │ │ │ │ │ │ ├── ToxEventListener.scala │ │ │ │ │ │ ├── SelfConnectionStatusCallback.scala │ │ │ │ │ │ ├── FriendConnectionStatusCallback.scala │ │ │ │ │ │ ├── FileRecvControlCallback.scala │ │ │ │ │ │ ├── FriendMessageCallback.scala │ │ │ │ │ │ ├── FileRecvChunkCallback.scala │ │ │ │ │ │ └── FileRecvCallback.scala │ │ │ │ │ └── enums │ │ │ │ │ │ ├── ToxProxyType.java │ │ │ │ │ │ ├── ToxMessageType.java │ │ │ │ │ │ ├── ToxUserStatus.java │ │ │ │ │ │ ├── ToxSavedataType.java │ │ │ │ │ │ ├── ToxFileControl.java │ │ │ │ │ │ ├── ToxConnection.java │ │ │ │ │ │ └── ToxFileKind.java │ │ │ │ ├── crypto │ │ │ │ │ ├── exceptions │ │ │ │ │ │ ├── Makefile │ │ │ │ │ │ ├── ToxEncryptionException.java │ │ │ │ │ │ ├── ToxKeyDerivationException.java │ │ │ │ │ │ └── ToxDecryptionException.java │ │ │ │ │ └── ToxCryptoConstants.scala │ │ │ │ ├── exceptions │ │ │ │ │ ├── ToxKilledException.java │ │ │ │ │ ├── ToxException.scala │ │ │ │ │ └── JavaOnly.java │ │ │ │ ├── impl │ │ │ │ │ └── jni │ │ │ │ │ │ ├── AutoGenerated.java │ │ │ │ │ │ ├── ToxCryptoJni.java │ │ │ │ │ │ └── ToxCryptoImpl.scala │ │ │ │ ├── ToxImplBase.scala │ │ │ │ └── mkexceptions │ │ │ │ └── core │ │ │ │ └── random │ │ │ │ └── RandomCore.scala │ │ └── test │ │ │ ├── java │ │ │ └── im │ │ │ │ └── tox │ │ │ │ ├── tox4j │ │ │ │ ├── av │ │ │ │ │ ├── package.scala │ │ │ │ │ └── bench │ │ │ │ │ │ ├── AvProfiling.scala │ │ │ │ │ │ └── AvCallbackTimingBench.scala │ │ │ │ ├── core │ │ │ │ │ ├── package.scala │ │ │ │ │ ├── bench │ │ │ │ │ │ ├── TravisBenchSuite.scala │ │ │ │ │ │ ├── IterateMemoryBench.scala │ │ │ │ │ │ ├── BenchWip.scala │ │ │ │ │ │ ├── IterateTimingBench.scala │ │ │ │ │ │ ├── ToxCoreTimingBench.scala │ │ │ │ │ │ └── SettersTimingBench.scala │ │ │ │ │ ├── exceptions │ │ │ │ │ │ ├── ToxGetPortExceptionTest.scala │ │ │ │ │ │ ├── ToxSetTypingExceptionTest.scala │ │ │ │ │ │ ├── ToxFriendGetPublicKeyExceptionTest.scala │ │ │ │ │ │ ├── ToxFriendByPublicKeyExceptionTest.scala │ │ │ │ │ │ ├── ToxFriendDeleteExceptionTest.scala │ │ │ │ │ │ ├── ToxFileSendExceptionTest.scala │ │ │ │ │ │ ├── ToxSetInfoExceptionTest.scala │ │ │ │ │ │ └── ToxFriendSendMessageExceptionTest.scala │ │ │ │ │ ├── callbacks │ │ │ │ │ │ ├── FriendConnectionStatusCallbackTest.scala │ │ │ │ │ │ ├── SelfConnectionStatusCallbackTest.scala │ │ │ │ │ │ ├── NameEmptyTest.scala │ │ │ │ │ │ ├── FilePauseResumeWithControlTest.scala │ │ │ │ │ │ ├── FriendNameCallbackTest.scala │ │ │ │ │ │ ├── FriendStatusMessageCallbackTest.scala │ │ │ │ │ │ ├── FilePauseResumeWithResendTest.scala │ │ │ │ │ │ ├── FriendLossyPacketCallbackTest.scala │ │ │ │ │ │ └── FriendLosslessPacketCallbackTest.scala │ │ │ │ │ ├── SmallNat.scala │ │ │ │ │ └── options │ │ │ │ │ │ ├── ToxOptionsTest.scala │ │ │ │ │ │ └── ProxyOptionsTest.scala │ │ │ │ ├── impl │ │ │ │ │ ├── package.scala │ │ │ │ │ └── jni │ │ │ │ │ │ ├── package.scala │ │ │ │ │ │ ├── ToxCryptoImplTest.scala │ │ │ │ │ │ ├── ToxAvNamingTest.scala │ │ │ │ │ │ ├── ToxCoreNamingTest.scala │ │ │ │ │ │ ├── NamingConventionsTest.scala │ │ │ │ │ │ ├── FinalizerTest.scala │ │ │ │ │ │ ├── internal │ │ │ │ │ │ └── EventTest.scala │ │ │ │ │ │ ├── codegen │ │ │ │ │ │ ├── CodeGenerator.scala │ │ │ │ │ │ ├── JniMethodRefs.scala │ │ │ │ │ │ └── JniConstants.scala │ │ │ │ │ │ └── MethodMap.scala │ │ │ │ ├── crypto │ │ │ │ │ ├── package.scala │ │ │ │ │ └── ToxCryptoConstantsTest.scala │ │ │ │ ├── TestConstants.scala │ │ │ │ ├── bench │ │ │ │ │ ├── picklers │ │ │ │ │ │ ├── Implicits.scala │ │ │ │ │ │ └── ClassPickler.scala │ │ │ │ │ ├── TimingReport.scala │ │ │ │ │ └── MemoryReport.scala │ │ │ │ ├── DhtNode.scala │ │ │ │ ├── ToxAvTestBase.scala │ │ │ │ ├── ConnectedListener.scala │ │ │ │ ├── exceptions │ │ │ │ │ ├── ToxKilledExceptionTest.scala │ │ │ │ │ └── ToxExceptionTest.scala │ │ │ │ └── JavaLibraryPath.scala │ │ │ │ ├── documentation │ │ │ │ └── Doc.scala │ │ │ │ └── gui │ │ │ │ ├── events │ │ │ │ ├── MessageTextOnKey.scala │ │ │ │ ├── BootstrapButtonOnAction.scala │ │ │ │ ├── AddFriendButtonOnAction.scala │ │ │ │ ├── SendFileButtonOnAction.scala │ │ │ │ └── SendButtonOnAction.scala │ │ │ │ ├── ToxGuiClient.scala │ │ │ │ ├── domain │ │ │ │ ├── FileTransfer.scala │ │ │ │ ├── Friend.scala │ │ │ │ ├── FileTransferOutgoing.scala │ │ │ │ └── FileTransferIncoming.scala │ │ │ │ └── forms │ │ │ │ └── MainViewBase.java │ │ │ ├── cpp │ │ │ ├── tox │ │ │ │ └── dummy.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── main.cpp │ │ │ └── mock_jni.h │ │ │ └── resources │ │ │ └── log4j.properties │ ├── local.sbt.example │ └── tools │ │ └── cmake │ │ └── FindGlog.cmake ├── macros │ ├── project │ │ ├── build.properties │ │ └── plugins.sbt │ ├── build.sbt │ └── src │ │ └── test │ │ └── scala │ │ └── im │ │ └── tox │ │ └── tox4j │ │ └── OptimisedIdOpsTest.scala └── linters │ ├── project │ ├── build.properties │ └── plugins.sbt │ ├── src │ ├── test │ │ └── scala │ │ │ ├── TravisBenchSuite.scala │ │ │ └── im │ │ │ └── tox │ │ │ └── tox4j │ │ │ └── lint │ │ │ ├── ToxOptionsClassesTest.scala │ │ │ └── OptionOrNullTest.scala │ └── main │ │ ├── resources │ │ └── warts.properties │ │ └── scala │ │ └── im │ │ └── tox │ │ └── tox4j │ │ └── lint │ │ └── OptionOrNull.scala │ └── build.sbt ├── tools ├── depgraph ├── git-install ├── ndk-install ├── dependency-analyser └── check-whitespace ├── .gitignore ├── AUTHORS.md ├── README.md └── .travis.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /projects/build-basic/project/src: -------------------------------------------------------------------------------- 1 | ../src -------------------------------------------------------------------------------- /projects/build-extra/project/src: -------------------------------------------------------------------------------- 1 | ../src -------------------------------------------------------------------------------- /projects/tox4j/android/.gitignore: -------------------------------------------------------------------------------- 1 | /*/ 2 | -------------------------------------------------------------------------------- /projects/tox4j/project/.gitignore: -------------------------------------------------------------------------------- 1 | /lib 2 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/_tags: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /projects/build-basic/project/depends.sbt: -------------------------------------------------------------------------------- 1 | ../depends.sbt -------------------------------------------------------------------------------- /projects/build-extra/project/depends.sbt: -------------------------------------------------------------------------------- 1 | ../depends.sbt -------------------------------------------------------------------------------- /projects/macros/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.9 2 | -------------------------------------------------------------------------------- /projects/tox4j/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.9 2 | -------------------------------------------------------------------------------- /projects/build-basic/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.9 2 | -------------------------------------------------------------------------------- /projects/build-extra/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.9 2 | -------------------------------------------------------------------------------- /projects/linters/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.9 2 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/tox/core.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/protocol.ml: -------------------------------------------------------------------------------- 1 | type t = 2 | | UDP 3 | | TCP 4 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Sources from SBT. 2 | include(${MAIN_FILE}) 3 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxAv/generated/impls.h: -------------------------------------------------------------------------------- 1 | // im.tox.tox4j.impl.jni.ToxAvJni 2 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/.merlin: -------------------------------------------------------------------------------- 1 | PKG sodium 2 | PKG async 3 | PKG async_unix 4 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/tox/av.cpp: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_TOXAV 2 | #include 3 | #endif 4 | -------------------------------------------------------------------------------- /projects/build-extra/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("im.tox" % "build-basic" % "0.1-SNAPSHOT") 2 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/publicKeyMap.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | include Map.Make(PublicKey) 3 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/exceptions/Makefile: -------------------------------------------------------------------------------- 1 | all: ../../mkexceptions exceptions.json 2 | $+ 3 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/Makefile: -------------------------------------------------------------------------------- 1 | all: ../../mkexceptions exceptions.json 2 | $+ 3 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/crypto/exceptions/Makefile: -------------------------------------------------------------------------------- 1 | all: ../../mkexceptions exceptions.json 2 | $+ 3 | -------------------------------------------------------------------------------- /projects/linters/src/test/scala/TravisBenchSuite.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.FlatSpec 2 | 3 | final class TravisBenchSuite extends FlatSpec 4 | -------------------------------------------------------------------------------- /projects/tox4j/android/local.i686-linux-android.sbt: -------------------------------------------------------------------------------- 1 | import sbt.tox4j.logic.jni.Platform._ 2 | jniSettings(Android("i686-linux-android")) 3 | -------------------------------------------------------------------------------- /projects/build-basic/src/test/scala/TravisBenchSuite.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.FlatSpec 2 | 3 | final class TravisBenchSuite extends FlatSpec 4 | -------------------------------------------------------------------------------- /projects/build-extra/src/test/scala/TravisBenchSuite.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.FlatSpec 2 | 3 | final class TravisBenchSuite extends FlatSpec 4 | -------------------------------------------------------------------------------- /projects/tox4j/android/local.arm-linux-androideabi.sbt: -------------------------------------------------------------------------------- 1 | import sbt.tox4j.logic.jni.Platform._ 2 | jniSettings(Android("arm-linux-androideabi")) 3 | -------------------------------------------------------------------------------- /projects/tox4j/local.sbt.example: -------------------------------------------------------------------------------- 1 | import sbt.tox4j.Benchmarking.Keys._ 2 | import sbt.tox4j.Benchmarking._ 3 | 4 | machine in Benchmark := "iphydf" 5 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/.gitignore: -------------------------------------------------------------------------------- 1 | /*/_build 2 | *.annot 3 | *.cmt 4 | *.cmti 5 | *.cmo 6 | *.cmi 7 | *.cmx 8 | *.o 9 | *.byte 10 | *.native 11 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/av/package.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import im.tox.documentation._ 4 | 5 | package object av extends Documented 6 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/package.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import im.tox.documentation._ 4 | 5 | package object core extends Documented 6 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/package.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import im.tox.documentation._ 4 | 5 | package object impl extends Documented 6 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/crypto/package.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import im.tox.documentation._ 4 | 5 | package object crypto extends Documented 6 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/package.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl 2 | 3 | import im.tox.documentation._ 4 | 5 | package object jni extends Documented 6 | -------------------------------------------------------------------------------- /projects/build-basic/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | // Test coverage. 2 | addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.1.0") 3 | addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.0.0.BETA1") 4 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/TestConstants.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | object TestConstants { 4 | final val Timeout = 60000L 5 | final val Iterations = 100 6 | } 7 | -------------------------------------------------------------------------------- /projects/linters/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" 2 | 3 | addSbtPlugin("im.tox" % "build-extra" % "0.1-SNAPSHOT") 4 | -------------------------------------------------------------------------------- /projects/macros/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" 2 | 3 | addSbtPlugin("im.tox" % "build-extra" % "0.1-SNAPSHOT") 4 | -------------------------------------------------------------------------------- /projects/tox4j/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" 2 | 3 | addSbtPlugin("im.tox" % "build-extra" % "0.1-SNAPSHOT") 4 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/ToxEventAdapter.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | class ToxEventAdapter[ToxCoreState] extends ToxEventListener[ToxCoreState] 4 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/callbacks/ToxAvEventAdapter.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.callbacks 2 | 3 | class ToxAvEventAdapter[ToxCoreState] extends ToxAvEventListener[ToxCoreState] 4 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/bench/picklers/Implicits.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.bench.picklers 2 | 3 | object Implicits { 4 | implicit def classPickler[T]: ClassPickler[T] = new ClassPickler[T] 5 | } 6 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/Makefile: -------------------------------------------------------------------------------- 1 | main.native: $(wildcard *.ml *.mli) Makefile 2 | ocamlbuild -use-ocamlfind -lflag -thread -cflag -thread -pkgs sodium,async,async_unix main.native 3 | 4 | clean: 5 | ocamlbuild -clean 6 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/ToxCryptoImplTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni 2 | 3 | import im.tox.tox4j.crypto.ToxCryptoTest 4 | 5 | final class ToxCryptoImplTest extends ToxCryptoTest(ToxCryptoImpl) 6 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/cpp/tox/dummy.cpp: -------------------------------------------------------------------------------- 1 | #include "tox/core.h" 2 | 3 | #include "util/logging.h" 4 | #include 5 | 6 | 7 | TEST (ToxCore, Dummy) { 8 | LOG (INFO) << "Dummy test"; 9 | EXPECT_TRUE (true); 10 | } 11 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/ToxAvNamingTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni 2 | 3 | import im.tox.tox4j.av.ToxAv 4 | 5 | final class ToxAvNamingTest extends NamingConventionsTest(classOf[ToxAvJni], classOf[ToxAv[_]]) 6 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/ToxCoreNamingTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni 2 | 3 | import im.tox.tox4j.core.ToxCore 4 | 5 | final class ToxCoreNamingTest extends NamingConventionsTest(classOf[ToxCoreJni], classOf[ToxCore[_]]) 6 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/sbt/tox4j/OptionalPlugin.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j 2 | 3 | import sbt._ 4 | 5 | // scalastyle:off 6 | abstract class OptionalPlugin extends Plugin { 7 | def Keys: Any 8 | def moduleSettings: Seq[Setting[_]] 9 | } 10 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/Build.lsp: -------------------------------------------------------------------------------- 1 | ((Name "toxcore") 2 | (Description "Tox protocol library") 3 | (Kind Program) 4 | 5 | (OCamlSources 6 | ("Main")) 7 | 8 | (OCamlRequires 9 | ("sodium" 10 | "async" 11 | "async_unix"))) 12 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/util/pp_cat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | * Preprocessor utility to concatenate two tokens. If one of the tokens is a 5 | * macro, it is evaluated before concatenation. 6 | */ 7 | #define PP_CAT(a, b) PP_CAT_(a, b) 8 | #define PP_CAT_(a, b) a##b 9 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | link_libraries(pthread sodium tox4j) 2 | 3 | if(DEFINED TEST_FILE) 4 | if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) 5 | include(${TEST_FILE}) 6 | else() 7 | message(STATUS "Not building tests from ${TEST_FILE} due to cross-compilation") 8 | endif() 9 | endif() 10 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/documentation/Doc.scala: -------------------------------------------------------------------------------- 1 | package im.tox.documentation 2 | 3 | sealed trait Doc { 4 | def reference: String 5 | } 6 | 7 | object Doc { 8 | final case class Ref(reference: String) extends Doc 9 | final case class Text(reference: String, body: String) extends Doc 10 | } 11 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/port.mli: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | 4 | type t = private int 5 | 6 | val min : t 7 | val max : t 8 | 9 | val of_int : int -> t option 10 | val to_int : t -> int 11 | 12 | val unpack : (Message.plain, t Or_error.t) Message.Consume.t 13 | val pack : (Message.plain, t) Message.Fill.t 14 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/bench/TravisBenchSuite.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.bench 2 | 3 | import im.tox.tox4j.bench.PerformanceReportBase 4 | 5 | final class TravisBenchSuite extends PerformanceReportBase { 6 | 7 | include[IterateTimingBench] 8 | include[IterateMemoryBench] 9 | 10 | } 11 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.Target=System.out 4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 5 | log4j.appender.stdout.layout.ConversionPattern=[%d{HH:mm:ss.SSS}] %-5p %c{1} - %m%n 6 | -------------------------------------------------------------------------------- /projects/linters/src/main/resources/warts.properties: -------------------------------------------------------------------------------- 1 | # Contains a list of wart remover classes. 2 | # TODO(iphydf): This one is broken for match/case on Option in tox4j. Fix it. 3 | #EqualsNone=im.tox.tox4j.lint.EqualsNone 4 | OptionOrNull=im.tox.tox4j.lint.OptionOrNull 5 | Override=im.tox.tox4j.lint.Override 6 | ToxOptionsClasses=im.tox.tox4j.lint.ToxOptionsClasses 7 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/util/pp_attributes.h: -------------------------------------------------------------------------------- 1 | #ifndef PP_ATTRIBUTES_H 2 | #define PP_ATTRIBUTES_H 3 | 4 | 5 | #if defined(__GNUC__) 6 | # define PP_UNUSED __attribute__ ((__unused__)) 7 | # define PP_NORETURN __attribute__ ((__noreturn__)) 8 | #else 9 | # define PP_NORETURN 10 | # define PP_UNUSED 11 | #endif 12 | 13 | 14 | #endif /* PP_ATTRIBUTES_H */ 15 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/callbacks/ToxAvEventListener.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.callbacks 2 | 3 | trait ToxAvEventListener[ToxCoreState] 4 | extends CallCallback[ToxCoreState] 5 | with CallStateCallback[ToxCoreState] 6 | with BitRateStatusCallback[ToxCoreState] 7 | with AudioReceiveFrameCallback[ToxCoreState] 8 | with VideoReceiveFrameCallback[ToxCoreState] 9 | -------------------------------------------------------------------------------- /projects/tox4j/android/toxcore.patch: -------------------------------------------------------------------------------- 1 | diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c 2 | index d7401de..1ba77a2 100644 3 | --- a/toxcore/TCP_server.c 4 | +++ b/toxcore/TCP_server.c 5 | @@ -32,6 +32,10 @@ 6 | 7 | #include "util.h" 8 | 9 | +#ifndef EPOLLRDHUP 10 | +#define EPOLLRDHUP 0x2000 11 | +#endif 12 | + 13 | /* return 1 on success 14 | * return 0 on failure 15 | */ 16 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCrypto/ToxCrypto.h: -------------------------------------------------------------------------------- 1 | // Instance manager, JNI utilities. 2 | #include "tox4j/Tox4j.h" 3 | 4 | // JNI declarations from javah. 5 | #include "im_tox_tox4j_impl_jni_ToxCryptoJni.h" 6 | 7 | // Header from toxcore. 8 | #include 9 | 10 | #define SUBSYSTEM TOX 11 | #define CLASS ToxCrypto 12 | #define PREFIX tox 13 | 14 | 15 | struct ToxCrypto; 16 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/nonce.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | open Sodium 3 | 4 | 5 | let random = Box.random_nonce 6 | 7 | 8 | let pack ~buf nonce = 9 | Box.Bytes.of_nonce nonce 10 | |> Bytes.unsafe_to_string 11 | |> Message.Fill.string buf 12 | 13 | 14 | let unpack ~buf = 15 | Message.Consume.string buf ~len:Box.nonce_size 16 | |> Bytes.unsafe_of_string 17 | |> Box.Bytes.to_nonce 18 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/util/unused.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /***************************************************************************** 4 | * 5 | * Identity and unused-value function. 6 | * 7 | *****************************************************************************/ 8 | 9 | static auto const identity = [](auto v) { return v; }; 10 | 11 | template static inline void unused (T const &...) { } 12 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/events/MessageTextOnKey.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.events 2 | 3 | import java.awt.event.{KeyAdapter, KeyEvent} 4 | 5 | import im.tox.gui.MainView 6 | 7 | final class MessageTextOnKey(toxGui: MainView) extends KeyAdapter { 8 | override def keyPressed(event: KeyEvent): Unit = { 9 | if (event.getKeyChar == '\n') { 10 | toxGui.sendButton.doClick() 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/enums/ToxProxyType.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.enums; 2 | 3 | /** 4 | * Type of proxy used to connect to TCP relays. 5 | */ 6 | public enum ToxProxyType { 7 | /** 8 | * Don't use a proxy. 9 | */ 10 | NONE, 11 | /** 12 | * HTTP proxy using CONNECT. 13 | */ 14 | HTTP, 15 | /** 16 | * SOCKS proxy for simple socket pipes. 17 | */ 18 | SOCKS5, 19 | } 20 | -------------------------------------------------------------------------------- /projects/build-extra/build.sbt: -------------------------------------------------------------------------------- 1 | organization := "im.tox" 2 | name := "build-extra" 3 | 4 | sbtPlugin := true 5 | 6 | // https://github.com/scoverage/sbt-scoverage#highlighting 7 | ScoverageSbtPlugin.ScoverageKeys.coverageHighlighting := false 8 | ScoverageSbtPlugin.ScoverageKeys.coverageMinimum := 0 9 | 10 | // Enable the plugins we want. 11 | sbt.tox4j.lint.Checkstyle.moduleSettings 12 | sbt.tox4j.lint.Scalastyle.moduleSettings 13 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/exceptions/ToxGetPortExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions 2 | 3 | import im.tox.tox4j.testing.ToxTestMixin 4 | import org.scalatest.FunSuite 5 | 6 | final class ToxGetPortExceptionTest extends FunSuite with ToxTestMixin { 7 | 8 | test("GetTcpPort_NotBound") { 9 | interceptWithTox(ToxGetPortException.Code.NOT_BOUND)( 10 | _.getTcpPort 11 | ) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/types.ml: -------------------------------------------------------------------------------- 1 | open Sodium 2 | 3 | 4 | type node = { 5 | n_proto : Protocol.t; 6 | n_addr : InetAddr.t; 7 | n_port : Port.t; 8 | n_key : Box.public_key; 9 | } 10 | 11 | 12 | type connected_node = { 13 | cn_node : node; 14 | cn_ckey : Box.channel_key; 15 | } 16 | 17 | 18 | type dht = { 19 | dht_sk : Box.secret_key; 20 | dht_pk : Box.public_key; 21 | dht_nodes : connected_node PublicKeyMap.t; 22 | } 23 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/exceptions/ToxSetTypingExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions 2 | 3 | import im.tox.tox4j.testing.ToxTestMixin 4 | import org.scalatest.FunSuite 5 | 6 | final class ToxSetTypingExceptionTest extends FunSuite with ToxTestMixin { 7 | 8 | test("SetTypingToNonExistent") { 9 | interceptWithTox(ToxSetTypingException.Code.FRIEND_NOT_FOUND)( 10 | _.setTyping(1, typing = true) 11 | ) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/sbt/tox4j/lint/Xlint.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j.lint 2 | 3 | import sbt.Keys._ 4 | import sbt.{AutoPlugin, PluginTrigger} 5 | 6 | object Xlint extends AutoPlugin { 7 | 8 | override def trigger: PluginTrigger = allRequirements 9 | 10 | override val projectSettings = Seq( 11 | scalacOptions ++= Seq("-Xlint", "-unchecked", "-feature", "-deprecation"), 12 | javacOptions ++= Seq("-Xlint:deprecation", "-Xlint:unchecked") 13 | ) 14 | 15 | } 16 | -------------------------------------------------------------------------------- /projects/linters/src/test/scala/im/tox/tox4j/lint/ToxOptionsClassesTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.lint 2 | 3 | import org.brianmckenna.wartremover.test.WartTestTraverser 4 | import org.scalatest.FunSuite 5 | 6 | final class ToxOptionsClassesTest extends FunSuite { 7 | 8 | test("non-options classes are not flagged") { 9 | val result = WartTestTraverser(ToxOptionsClasses) { 10 | class Foo(thing: Any) 11 | } 12 | 13 | assert(result.errors == Nil) 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/cpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include "util/logging.h" 2 | #include 3 | 4 | #include 5 | 6 | int 7 | main (int argc, char **argv) 8 | { 9 | google::InitGoogleLogging (argv[0]); 10 | testing::InitGoogleTest (&argc, argv); 11 | 12 | google::LogToStderr (); 13 | 14 | int result = RUN_ALL_TESTS (); 15 | 16 | google::ShutdownGoogleLogging (); 17 | google::protobuf::ShutdownProtobufLibrary (); 18 | 19 | return result; 20 | } 21 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/ToxGuiClient.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui 2 | 3 | import javax.swing._ 4 | 5 | /** 6 | * Run a Tox GUI client with Nimbus L&F. 7 | */ 8 | object ToxGuiClient extends App { 9 | 10 | for { 11 | info <- UIManager.getInstalledLookAndFeels 12 | if info.getName == "Nimbus" 13 | } { 14 | UIManager.setLookAndFeel(info.getClassName) 15 | } 16 | 17 | val dialog = new MainView 18 | dialog.pack() 19 | dialog.setVisible(true) 20 | 21 | } 22 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/exceptions/ToxFriendGetPublicKeyExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions 2 | 3 | import im.tox.tox4j.testing.ToxTestMixin 4 | import org.scalatest.FunSuite 5 | 6 | final class ToxFriendGetPublicKeyExceptionTest extends FunSuite with ToxTestMixin { 7 | 8 | test("FriendNotFound") { 9 | interceptWithTox(ToxFriendGetPublicKeyException.Code.FRIEND_NOT_FOUND)( 10 | _.getFriendPublicKey(1) 11 | ) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/exceptions/ToxKilledException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.exceptions; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | /** 6 | * Exception to be thrown when a method is invoked on a tox instance that has been closed. 7 | * 8 | * @author Simon Levermann (sonOfRa) 9 | */ 10 | public final class ToxKilledException extends RuntimeException { 11 | 12 | public ToxKilledException(@NotNull String message) { 13 | super(message); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/DhtNode.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | final case class DhtNode(ipv4: String, ipv6: String, udpPort: Int, tcpPort: Int, dhtId: Array[Byte]) { 4 | 5 | def this(ipv4: String, ipv6: String, udpPort: Int, tcpPort: Int, dhtId: String) { 6 | this(ipv4, ipv6, udpPort, tcpPort, ToxCoreTestBase.parsePublicKey(dhtId)) 7 | } 8 | 9 | def this(ipv4: String, ipv6: String, port: Int, dhtId: String) { 10 | this(ipv4, ipv6, port, port, dhtId) 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /projects/tox4j/android/protobuf.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/Makefile.am b/src/Makefile.am 2 | index 5b28579..6fa4d35 100644 3 | --- a/src/Makefile.am 4 | +++ b/src/Makefile.am 5 | @@ -597,7 +597,7 @@ protoc_outputs = \ 6 | google/protobuf/util/json_format_proto3.pb.cc \ 7 | google/protobuf/util/json_format_proto3.pb.h 8 | 9 | -BUILT_SOURCES = $(protoc_outputs) 10 | +#BUILT_SOURCES = $(protoc_outputs) 11 | 12 | if USE_EXTERNAL_PROTOC 13 | 14 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/tox/core.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "tox/common.h" 4 | #include 5 | 6 | 7 | namespace tox 8 | { 9 | struct core_deleter 10 | { 11 | void operator () (Tox *tox) 12 | { 13 | tox_kill (tox); 14 | } 15 | }; 16 | 17 | typedef std::unique_ptr core_ptr; 18 | 19 | #define CALLBACK(NAME) using callback_##NAME = detail::cb; 20 | #include "generated/core.h" 21 | #undef CALLBACK 22 | } 23 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/enums/ToxMessageType.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.enums; 2 | 3 | /** 4 | * Represents message types for {@link im.tox.tox4j.core.ToxCore#friendSendMessage} and group chat 5 | * messages. 6 | */ 7 | public enum ToxMessageType { 8 | /** 9 | * Normal text message. Similar to PRIVMSG on IRC. 10 | */ 11 | NORMAL, 12 | /** 13 | * A message describing an user action. This is similar to /me (CTCP ACTION) 14 | * on IRC. 15 | */ 16 | ACTION, 17 | } 18 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/ToxAvTestBase.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import im.tox.tox4j.core.ToxCoreFactory 4 | import im.tox.tox4j.impl.jni.{ToxAvImpl, ToxCoreImpl} 5 | 6 | object ToxAvTestBase { 7 | 8 | final val enabled = { 9 | try { 10 | ToxCoreFactory.withTox { tox => 11 | new ToxAvImpl[Unit](tox.asInstanceOf[ToxCoreImpl[Unit]]).close() 12 | true 13 | } 14 | } catch { 15 | case _: UnsatisfiedLinkError => false 16 | } 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/tox/generated/av.h: -------------------------------------------------------------------------------- 1 | // im.tox.tox4j.av.callbacks.AudioReceiveFrameCallback#audioReceiveFrame 2 | CALLBACK (audio_receive_frame) 3 | // im.tox.tox4j.av.callbacks.BitRateStatusCallback#bitRateStatus 4 | CALLBACK (bit_rate_status) 5 | // im.tox.tox4j.av.callbacks.CallCallback#call 6 | CALLBACK (call) 7 | // im.tox.tox4j.av.callbacks.CallStateCallback#callState 8 | CALLBACK (call_state) 9 | // im.tox.tox4j.av.callbacks.VideoReceiveFrameCallback#videoReceiveFrame 10 | CALLBACK (video_receive_frame) 11 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/domain/FileTransfer.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.domain 2 | 3 | import java.io.{Closeable, File, FileNotFoundException, IOException} 4 | 5 | abstract class FileTransfer(val file: File) extends Closeable { 6 | @throws[FileNotFoundException] 7 | def resume() 8 | 9 | @throws[IOException] 10 | def read(position: Long, length: Int): Array[Byte] 11 | 12 | @throws[IOException] 13 | def close() 14 | 15 | @throws[IOException] 16 | def write(position: Long, data: Array[Byte]) 17 | } 18 | -------------------------------------------------------------------------------- /projects/tox4j/android/libvpx.patch: -------------------------------------------------------------------------------- 1 | diff --git a/build/make/Makefile b/build/make/Makefile 2 | index da5721a..5a701eb 100644 3 | --- a/build/make/Makefile 4 | +++ b/build/make/Makefile 5 | @@ -124,6 +124,8 @@ else 6 | STACKREALIGN= 7 | endif 8 | 9 | +$(BUILD_PFX)%_neon.c.d: CFLAGS += -mfloat-abi=softfp -mfpu=neon 10 | +$(BUILD_PFX)%_neon.c.o: CFLAGS += -mfloat-abi=softfp -mfpu=neon 11 | $(BUILD_PFX)%_mmx.c.d: CFLAGS += -mmmx 12 | $(BUILD_PFX)%_mmx.c.o: CFLAGS += -mmmx 13 | $(BUILD_PFX)%_sse2.c.d: CFLAGS += -msse2 $(STACKREALIGN) 14 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/exceptions/ToxException.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.exceptions 2 | 3 | import org.jetbrains.annotations.NotNull 4 | 5 | abstract class ToxException[E <: Enum[E]](errorCode: E, message: String) extends Exception(message) { 6 | 7 | @NotNull 8 | final override def getMessage: String = { 9 | message match { 10 | case "" => "Error code: " + errorCode.name 11 | case _ => message + ", error code: " + errorCode.name 12 | } 13 | } 14 | 15 | final def code: E = errorCode 16 | 17 | } 18 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/port.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | 4 | exception Range_error 5 | 6 | type t = int 7 | 8 | let min = 0 9 | let max = 65535 10 | 11 | 12 | let of_int i = 13 | if i < min || i > max then 14 | None 15 | else 16 | Some i 17 | 18 | 19 | let to_int = Fn.id 20 | 21 | 22 | let unpack buf = 23 | match of_int (Message.Consume.uint16_be buf) with 24 | | None -> 25 | Or_error.of_exn Range_error 26 | | Some port -> 27 | Or_error.return port 28 | 29 | 30 | let pack = Message.Fill.uint16_be 31 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/sbt/tox4j/lint/Scalastyle.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j.lint 2 | 3 | import org.scalastyle.sbt.ScalastylePlugin.scalastyleConfigUrl 4 | import sbt._ 5 | import sbt.tox4j.OptionalPlugin 6 | 7 | object Scalastyle extends OptionalPlugin { 8 | object Keys 9 | 10 | private def config(suffix: String) = Some(getClass.getResource(s"scalastyle$suffix-config.xml")) 11 | 12 | override val moduleSettings = Seq( 13 | scalastyleConfigUrl := config(""), 14 | scalastyleConfigUrl in Test := config("-test") 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/tox/av.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "tox/common.h" 4 | #include 5 | 6 | #ifdef TOXAV_VERSION_MAJOR 7 | namespace tox 8 | { 9 | struct av_deleter 10 | { 11 | void operator () (ToxAV *toxav) 12 | { 13 | toxav_kill (toxav); 14 | } 15 | }; 16 | 17 | typedef std::unique_ptr av_ptr; 18 | 19 | #define CALLBACK(NAME) using callback_##NAME = detail::cb; 20 | #include "generated/av.h" 21 | #undef CALLBACK 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /tools/depgraph: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | PREFIX := target/scala-2.11/classes 4 | 5 | CLASSES := $(shell find $(PREFIX) -type f -name "*.class") 6 | BYTECODES := $(CLASSES:.class=.bc) 7 | 8 | %.bc: %.class 9 | @echo '$(subst /,.,$(patsubst $(PREFIX)/%.class,%,$<))' 10 | @cd $(PREFIX) && \ 11 | javap -c -p '$(subst /,.,$(patsubst $(PREFIX)/%.class,%,$<))' \ 12 | > '$(patsubst $(PREFIX)/%.class,%.bc,$<)' 13 | 14 | dependency-graph: $(BYTECODES) 15 | @tools/dependency-analyser $(foreach F,$^,'$F') 16 | 17 | clean: 18 | $(RM) $(BYTECODES) 19 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/org/scalastyle/scalariform/AstChecker.scala: -------------------------------------------------------------------------------- 1 | package org.scalastyle.scalariform 2 | 3 | import org.scalastyle.{CombinedAst, CombinedChecker, Lines, ScalastyleError} 4 | 5 | import scalariform.parser.CompilationUnit 6 | 7 | abstract class AstChecker(override val errorKey: String) extends CombinedChecker { 8 | def verify(ast: CompilationUnit, lines: Lines): List[ScalastyleError] 9 | 10 | override def verify(input: CombinedAst): List[ScalastyleError] = { 11 | verify(input.compilationUnit, input.lines) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendNameCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import org.jetbrains.annotations.NotNull 4 | 5 | /** 6 | * This event is triggered when a friend changes their name. 7 | */ 8 | trait FriendNameCallback[ToxCoreState] { 9 | /** 10 | * @param friendNumber The friend number of the friend whose name changed. 11 | * @param name The new nickname. 12 | */ 13 | def friendName( 14 | friendNumber: Int, @NotNull name: Array[Byte] 15 | )(state: ToxCoreState): ToxCoreState = state 16 | } 17 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/enums/ToxUserStatus.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.enums; 2 | 3 | /** 4 | * Represents the possible statuses a client can have. 5 | */ 6 | public enum ToxUserStatus { 7 | /** 8 | * User is online and available. 9 | */ 10 | NONE, 11 | /** 12 | * User is away. Clients can set this e.g. after a user defined 13 | * inactivity time. 14 | */ 15 | AWAY, 16 | /** 17 | * User is busy. Signals to other clients that this client does not 18 | * currently wish to communicate. 19 | */ 20 | BUSY, 21 | } 22 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/crypto/ToxCryptoConstantsTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.crypto 2 | 3 | import org.scalatest.FunSuite 4 | 5 | final class ToxCryptoConstantsTest extends FunSuite { 6 | 7 | test("HashLength") { 8 | assert(ToxCryptoConstants.HashLength >= 32) 9 | } 10 | 11 | test("EncryptionExtraLength contains at least a hash") { 12 | assert(ToxCryptoConstants.EncryptionExtraLength >= ToxCryptoConstants.HashLength) 13 | } 14 | 15 | test("SaltLength") { 16 | assert(ToxCryptoConstants.SaltLength >= 32) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/callbacks/CallCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.callbacks 2 | 3 | /** 4 | * Triggered when a friend calls us. 5 | */ 6 | trait CallCallback[ToxCoreState] { 7 | /** 8 | * @param friendNumber The friend number from which the call is incoming. 9 | * @param audioEnabled True if friend is sending audio. 10 | * @param videoEnabled True if friend is sending video. 11 | */ 12 | def call( 13 | friendNumber: Int, audioEnabled: Boolean, videoEnabled: Boolean 14 | )(state: ToxCoreState): ToxCoreState = state 15 | } 16 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendTypingCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | /** 4 | * This event is triggered when a friend starts or stops typing. 5 | */ 6 | trait FriendTypingCallback[ToxCoreState] { 7 | /** 8 | * @param friendNumber The friend number of the friend who started or stopped typing. 9 | * @param isTyping Whether the friend started (true) or stopped (false) typing. 10 | */ 11 | def friendTyping( 12 | friendNumber: Int, isTyping: Boolean 13 | )(state: ToxCoreState): ToxCoreState = state 14 | } 15 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/enums/ToxSavedataType.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.enums; 2 | 3 | import im.tox.tox4j.core.ToxCoreConstants; 4 | 5 | /** 6 | * Type of savedata to create the Tox instance from. 7 | */ 8 | public enum ToxSavedataType { 9 | /** 10 | * No savedata. 11 | */ 12 | NONE, 13 | /** 14 | * Savedata is one that was obtained from {@link im.tox.tox4j.core.ToxCore#getSavedata}. 15 | */ 16 | TOX_SAVE, 17 | /** 18 | * Savedata is a secret key of length {@link ToxCoreConstants#SecretKeySize}. 19 | */ 20 | SECRET_KEY, 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # GitHub pages. 2 | /.web 3 | 4 | # SBT compiled build system. 5 | /projects/*/project/project 6 | /projects/*/project/target 7 | 8 | # SBT output directory. 9 | /projects/*/target 10 | 11 | # Generated startup scripts for main classes. 12 | /projects/*/bin 13 | 14 | # Local user settings for SBT. 15 | /projects/*/local.sbt 16 | 17 | # IDEA meta files. 18 | .idea 19 | 20 | # Temporary editor files. 21 | *.swp 22 | *~ 23 | 24 | # Virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | 27 | # JNI configure output 28 | config.log 29 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/ConnectedListener.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import im.tox.tox4j.core.callbacks.ToxEventListener 4 | import im.tox.tox4j.core.enums.ToxConnection 5 | import org.jetbrains.annotations.NotNull 6 | 7 | final class ConnectedListener extends ToxEventListener[Unit] { 8 | 9 | @NotNull private var value = ToxConnection.NONE 10 | 11 | override def selfConnectionStatus(@NotNull connectionStatus: ToxConnection)(state: Unit): Unit = { 12 | value = connectionStatus 13 | } 14 | 15 | def isConnected: Boolean = value != ToxConnection.NONE 16 | 17 | } 18 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCrypto/hash.cpp: -------------------------------------------------------------------------------- 1 | #include "ToxCrypto.h" 2 | 3 | #include // For TOX_HASH_LENGTH 4 | 5 | 6 | /* 7 | * Class: im_tox_tox4j_impl_jni_ToxCryptoJni 8 | * Method: toxHash 9 | * Signature: ([B)[B 10 | */ 11 | JNIEXPORT jbyteArray JNICALL Java_im_tox_tox4j_impl_jni_ToxCryptoJni_toxHash 12 | (JNIEnv *env, jclass, jbyteArray dataArray) 13 | { 14 | ByteArray data (env, dataArray); 15 | std::vector hash (TOX_HASH_LENGTH); 16 | bool result = tox_hash (hash.data (), data.data (), data.size ()); 17 | tox4j_assert (result); 18 | return toJavaArray (env, hash); 19 | } 20 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendStatusMessageCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import org.jetbrains.annotations.NotNull 4 | 5 | /** 6 | * This event is triggered when a friend changes their status message. 7 | */ 8 | trait FriendStatusMessageCallback[ToxCoreState] { 9 | /** 10 | * @param friendNumber The friend number of the friend whose status message changed. 11 | * @param message The new status message. 12 | */ 13 | def friendStatusMessage( 14 | friendNumber: Int, @NotNull message: Array[Byte] 15 | )(state: ToxCoreState): ToxCoreState = state 16 | } 17 | -------------------------------------------------------------------------------- /projects/build-basic/build.sbt: -------------------------------------------------------------------------------- 1 | organization := "im.tox" 2 | name := "build-basic" 3 | 4 | sbtPlugin := true 5 | 6 | // https://github.com/scoverage/sbt-scoverage#highlighting 7 | ScoverageSbtPlugin.ScoverageKeys.coverageHighlighting := false 8 | ScoverageSbtPlugin.ScoverageKeys.coverageMinimum := 0 9 | 10 | // Enable the plugins we want. Here we also need to explicitly apply AutoPlugins, 11 | // because they are not loaded correctly by SBT in our bootstrap. 12 | sbt.tox4j.lint.Checkstyle.moduleSettings 13 | sbt.tox4j.lint.Scalastyle.moduleSettings 14 | sbt.tox4j.Benchmarking.projectSettings 15 | sbt.tox4j.CodeFormat.projectSettings 16 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/echoRequest.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | open Types 3 | 4 | 5 | let kind = Packet.Kind.EchoRequest 6 | type t = Packet.Data.echo_request = { 7 | ping_id : int64; 8 | } 9 | 10 | 11 | let wrap decoded = 12 | Packet.Data.EchoRequest decoded 13 | 14 | 15 | let unpack ~dht ~buf = 16 | DhtPacket.unpack ~dht ~buf 17 | ~f:( 18 | fun ~buf -> 19 | Or_error.return { ping_id = Message.Consume.int64_t_be buf } 20 | ) 21 | 22 | 23 | let pack ~dht ~buf ~node ~packet = 24 | DhtPacket.pack ~dht ~buf ~node ~kind ~f:( 25 | fun ~buf -> 26 | Message.Fill.int64_t_be buf packet.ping_id 27 | ) 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendStatusCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxUserStatus 4 | import org.jetbrains.annotations.NotNull 5 | 6 | /** 7 | * This event is triggered when a friend changes their user status. 8 | */ 9 | trait FriendStatusCallback[ToxCoreState] { 10 | /** 11 | * @param friendNumber The friend number of the friend whose user status changed. 12 | * @param status The new user status. 13 | */ 14 | def friendStatus( 15 | friendNumber: Int, @NotNull status: ToxUserStatus 16 | )(state: ToxCoreState): ToxCoreState = state 17 | } 18 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/echoResponse.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | open Types 3 | 4 | 5 | let kind = Packet.Kind.EchoResponse 6 | type t = Packet.Data.echo_response = { 7 | ping_id : int64; 8 | } 9 | 10 | 11 | let wrap decoded = 12 | Packet.Data.EchoResponse decoded 13 | 14 | 15 | let unpack ~dht ~buf = 16 | DhtPacket.unpack ~dht ~buf 17 | ~f:( 18 | fun ~buf -> 19 | Or_error.return { ping_id = Message.Consume.int64_t_be buf } 20 | ) 21 | 22 | 23 | let pack ~dht ~buf ~node ~packet = 24 | DhtPacket.pack ~dht ~buf ~node ~kind ~f:( 25 | fun ~buf -> 26 | Message.Fill.int64_t_be buf packet.ping_id; 27 | ) 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/exceptions/ToxFriendByPublicKeyExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions 2 | 3 | import im.tox.tox4j.testing.ToxTestMixin 4 | import org.scalatest.FunSuite 5 | 6 | final class ToxFriendByPublicKeyExceptionTest extends FunSuite with ToxTestMixin { 7 | 8 | test("Null") { 9 | interceptWithTox(ToxFriendByPublicKeyException.Code.NULL)( 10 | _.friendByPublicKey(null) 11 | ) 12 | } 13 | 14 | test("NotFound") { 15 | interceptWithTox(ToxFriendByPublicKeyException.Code.NOT_FOUND) { tox => 16 | tox.friendByPublicKey(tox.getPublicKey) 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/sbt/tox4j/CodeFormat.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j 2 | 3 | import com.typesafe.sbt.SbtScalariform.{ScalariformKeys, scalariformSettings} 4 | import sbt.{AutoPlugin, PluginTrigger} 5 | 6 | import scalariform.formatter.preferences._ 7 | 8 | object CodeFormat extends AutoPlugin { 9 | 10 | override def trigger: PluginTrigger = allRequirements 11 | 12 | override val projectSettings = scalariformSettings ++ Seq( 13 | ScalariformKeys.preferences := ScalariformKeys.preferences.value 14 | .setPreference(AlignSingleLineCaseStatements, true) 15 | .setPreference(DoubleIndentClassDeclaration, true) 16 | ) 17 | 18 | } 19 | -------------------------------------------------------------------------------- /projects/build-extra/depends.sbt: -------------------------------------------------------------------------------- 1 | resolvers += Classpaths.sbtPluginReleases 2 | resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" 3 | 4 | // Import build-basic transitively. 5 | addSbtPlugin("im.tox" % "build-basic" % "0.1-SNAPSHOT") 6 | 7 | // Code style. 8 | addSbtPlugin("org.brianmckenna" % "sbt-wartremover" % "0.13") 9 | 10 | // Test coverage. 11 | addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.1.0") 12 | addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.0.0.BETA1") 13 | 14 | // Test dependencies. 15 | libraryDependencies ++= Seq( 16 | "org.scalatest" %% "scalatest" % "2.2.4" 17 | ) map (_ % Test) 18 | -------------------------------------------------------------------------------- /projects/linters/build.sbt: -------------------------------------------------------------------------------- 1 | organization := "im.tox" 2 | name := "linters" 3 | scalaVersion := "2.11.7" 4 | 5 | // Build dependencies. 6 | libraryDependencies ++= Seq( 7 | "org.brianmckenna" %% "wartremover" % "0.13" 8 | ) 9 | 10 | // Test dependencies. 11 | libraryDependencies ++= Seq( 12 | "org.scalatest" %% "scalatest" % "2.2.4" 13 | ) map (_ % Test) 14 | 15 | // Scala macros. 16 | addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0-M5" cross CrossVersion.full) 17 | 18 | // Enable the plugins we want. 19 | sbt.tox4j.lint.Checkstyle.moduleSettings 20 | sbt.tox4j.lint.Scalastyle.moduleSettings 21 | sbt.tox4j.CodeFormat.projectSettings 22 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/Tox4j.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | 6 | /* 7 | * Do setup here. Caching of needed java method IDs etc should be done in this 8 | * function. It is guaranteed to be called when the library is loaded, and 9 | * nothing else will be called before this function is called. 10 | */ 11 | jint 12 | JNI_OnLoad (JavaVM *, void *) 13 | { 14 | if (!TOX_VERSION_IS_ABI_COMPATIBLE ()) 15 | return -1; 16 | return JNI_VERSION_1_4; 17 | } 18 | 19 | extern "C" void __gcov_flush (); 20 | 21 | void 22 | JNI_OnUnload (JavaVM, void *) 23 | { 24 | #ifndef __ANDROID__ 25 | __gcov_flush (); 26 | #endif 27 | } 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/cpp14compat.h: -------------------------------------------------------------------------------- 1 | #if 0 2 | extern "C" char *gets (char *); 3 | #endif 4 | 5 | #if !defined(HAVE_MAKE_UNIQUE) 6 | #include 7 | 8 | namespace std { 9 | template 10 | unique_ptr 11 | make_unique (Args &&...args) 12 | { 13 | return std::unique_ptr (new T (std::forward (args)...)); 14 | } 15 | } 16 | #endif 17 | 18 | #if !defined(HAVE_TO_STRING) 19 | #include 20 | 21 | namespace std { 22 | template 23 | string 24 | to_string (T const &v) 25 | { 26 | ostringstream out; 27 | out << v; 28 | return out.str (); 29 | } 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/bench/TimingReport.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.bench 2 | 3 | /** 4 | * Base class for timing benchmarks. Use the `timing` method at the top level and any other DSL statements inside. Do 5 | * not use `performance of` at the top level, as it will not use [[PerformanceReportBase.defaultConfig]]. 6 | */ 7 | abstract class TimingReport extends PerformanceReportBase { 8 | 9 | object timing extends Serializable { // scalastyle:ignore object.name 10 | def of(modulename: String): Scope = performance of modulename config defaultConfig 11 | def of[T](clazz: Class[T]): Scope = of(clazz.getSimpleName) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxAv/ToxAv.cpp: -------------------------------------------------------------------------------- 1 | #include "ToxAv.h" 2 | 3 | #ifdef TOXAV_VERSION_MAJOR 4 | 5 | using namespace av; 6 | 7 | void 8 | reference_symbols_av () 9 | { 10 | int toxav_finalize; // For Java only. 11 | 12 | #define JAVA_METHOD_REF(NAME) unused (JAVA_METHOD_NAME (NAME)); 13 | #define CXX_FUNCTION_REF(NAME) unused (NAME); 14 | #include "generated/natives.h" 15 | #undef CXX_FUNCTION_REF 16 | #undef JAVA_METHOD_REF 17 | } 18 | 19 | ToxInstances> av::instances; 20 | 21 | template<> extern char const *const module_name = "av"; 22 | template<> extern char const *const exn_prefix = "av"; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxGetPortException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxGetPortException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The instance was not bound to any port. 11 | */ 12 | NOT_BOUND, 13 | } 14 | 15 | public ToxGetPortException(@NotNull Code code) { 16 | this(code, ""); 17 | } 18 | 19 | public ToxGetPortException(@NotNull Code code, String message) { 20 | super(code, message); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendLossyPacketCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import org.jetbrains.annotations.NotNull 4 | 5 | /** 6 | * This event is triggered when a custom lossy packet arrives from a friend. 7 | */ 8 | trait FriendLossyPacketCallback[ToxCoreState] { 9 | /** 10 | * @param friendNumber The friend number of the friend who sent a lossy packet. 11 | * @param data A byte array containing the received packet data. The first byte is the packet id. 12 | */ 13 | def friendLossyPacket( 14 | friendNumber: Int, @NotNull data: Array[Byte] 15 | )(state: ToxCoreState): ToxCoreState = state 16 | } 17 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxAv/ToxAv.h: -------------------------------------------------------------------------------- 1 | // Instance manager, JNI utilities. 2 | #include "tox4j/Tox4j.h" 3 | 4 | // Protobuf classes. 5 | #include "Av.pb.h" 6 | 7 | // JNI declarations from javah. 8 | #include "im_tox_tox4j_impl_jni_ToxAvJni.h" 9 | 10 | // Header from toxcore. 11 | #include 12 | 13 | #ifndef SUBSYSTEM 14 | #define SUBSYSTEM TOXAV 15 | #define CLASS ToxAv 16 | #define PREFIX toxav 17 | #endif 18 | 19 | #ifdef TOXAV_VERSION_MAJOR 20 | namespace av 21 | { 22 | namespace proto = im::tox::tox4j::av::proto; 23 | 24 | using Events = proto::AvEvents; 25 | 26 | extern ToxInstances> instances; 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/bench/picklers/ClassPickler.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.bench.picklers 2 | 3 | import org.scalameter.picklers.Implicits._ 4 | import org.scalameter.picklers.Pickler 5 | 6 | final class ClassPickler[T] extends Pickler[Class[T]] { 7 | 8 | override def pickle(x: Class[T]): Array[Byte] = { 9 | implicitly[Pickler[String]].pickle(x.getCanonicalName) 10 | } 11 | 12 | override def unpickle(a: Array[Byte], from: Int): (Class[T], Int) = { 13 | val (className, next) = implicitly[Pickler[String]].unpickle(a, from) 14 | val unpickledClass = Class.forName(className) 15 | (unpickledClass.asInstanceOf[Class[T]], next) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/NamingConventionsTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni 2 | 3 | import org.scalatest.FunSuite 4 | 5 | abstract class NamingConventionsTest(jniClass: Class[_], traitClass: Class[_]) extends FunSuite { 6 | 7 | val exemptions = Seq("callback", "load", "close", "create") 8 | 9 | test("Java method names should be derivable from JNI method names") { 10 | val jniMethods = MethodMap(jniClass) 11 | 12 | traitClass 13 | .getDeclaredMethods.toSeq 14 | .map(_.getName) 15 | .filterNot(exemptions.contains) 16 | .foreach { name => 17 | assert(jniMethods.contains(name)) 18 | } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendLosslessPacketCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import org.jetbrains.annotations.NotNull 4 | 5 | /** 6 | * This event is triggered when a custom lossless packet arrives from a friend. 7 | */ 8 | trait FriendLosslessPacketCallback[ToxCoreState] { 9 | /** 10 | * @param friendNumber The friend number of the friend who sent a lossless packet. 11 | * @param data A byte array containing the received packet data. The first byte is the packet id. 12 | */ 13 | def friendLosslessPacket( 14 | friendNumber: Int, @NotNull data: Array[Byte] 15 | )(state: ToxCoreState): ToxCoreState = state 16 | } 17 | -------------------------------------------------------------------------------- /projects/build-extra/src/main/scala/sbt/tox4j/lint/Foursquare.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j.lint 2 | 3 | import sbt.Keys._ 4 | import sbt._ 5 | import sbt.tox4j.OptionalPlugin 6 | 7 | object Foursquare extends OptionalPlugin { 8 | 9 | object Keys 10 | 11 | // Enable foursquare linter. 12 | override val moduleSettings = Seq( 13 | resolvers ++= Seq( 14 | "Linter Repository" at "https://hairyfotr.github.io/linteRepo/releases", 15 | Resolver.sonatypeRepo("snapshots") 16 | ), 17 | addCompilerPlugin("org.psywerx.hairyfotr" %% "linter" % "0.1-SNAPSHOT"), 18 | scalacOptions in Test += "-P:linter:disable:IdenticalStatements+VariableAssignedUnusedValue" 19 | ) 20 | 21 | } 22 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxSetTypingException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxSetTypingException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The friendNumber passed did not designate a valid friend. 11 | */ 12 | FRIEND_NOT_FOUND, 13 | } 14 | 15 | public ToxSetTypingException(@NotNull Code code) { 16 | this(code, ""); 17 | } 18 | 19 | public ToxSetTypingException(@NotNull Code code, String message) { 20 | super(code, message); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/tox4j/Tox4j.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ToxInstances.h" 4 | #include "util/jniutil.h" 5 | #include "util/pp_cat.h" 6 | 7 | 8 | #define JAVA_METHOD_NAME(NAME) \ 9 | PP_CAT(Java_im_tox_tox4j_impl_jni_, PP_CAT(CLASS, PP_CAT(Jni_, NAME))) 10 | 11 | #define TOX_METHOD_NAME(NAME) \ 12 | JAVA_METHOD_NAME(PP_CAT(PREFIX, NAME)) 13 | 14 | 15 | #define JNI_METHOD(TYPE, NAME, ...) \ 16 | extern "C" JNIEXPORT TYPE JNICALL NAME \ 17 | (JNIEnv *env, jclass, __VA_ARGS__) 18 | 19 | #define JAVA_METHOD(TYPE, NAME, ...) \ 20 | JNI_METHOD(TYPE, JAVA_METHOD_NAME(NAME), __VA_ARGS__) 21 | 22 | #define TOX_METHOD(TYPE, NAME, ...) \ 23 | JNI_METHOD(TYPE, TOX_METHOD_NAME(NAME), __VA_ARGS__) 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendDeleteException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFriendDeleteException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * There was no friend with the given friend number. No friends were deleted. 11 | */ 12 | FRIEND_NOT_FOUND, 13 | } 14 | 15 | public ToxFriendDeleteException(@NotNull Code code) { 16 | this(code, ""); 17 | } 18 | 19 | public ToxFriendDeleteException(@NotNull Code code, String message) { 20 | super(code, message); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendReadReceiptCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.ToxCore 4 | 5 | /** 6 | * This event is triggered when the friend receives the message sent with 7 | * [[ToxCore.friendSendMessage]] with the corresponding message ID. 8 | */ 9 | trait FriendReadReceiptCallback[ToxCoreState] { 10 | /** 11 | * @param friendNumber The friend number of the friend who received the message. 12 | * @param messageId The message ID as returned from [[ToxCore.friendSendMessage]] corresponding to the message sent. 13 | */ 14 | def friendReadReceipt( 15 | friendNumber: Int, messageId: Int 16 | )(state: ToxCoreState): ToxCoreState = state 17 | } 18 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendGetPublicKeyException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFriendGetPublicKeyException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The friendNumber passed did not designate a valid friend. 11 | */ 12 | FRIEND_NOT_FOUND, 13 | } 14 | 15 | public ToxFriendGetPublicKeyException(@NotNull Code code) { 16 | this(code, ""); 17 | } 18 | 19 | public ToxFriendGetPublicKeyException(@NotNull Code code, String message) { 20 | super(code, message); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/exceptions/JavaOnly.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.exceptions; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Annotation to mark error codes in Java exception enums as Java-only, so they are not emitted as part of the error 10 | * code conversion fragments in C++ (see {@link im.tox.tox4j.impl.jni.codegen.JniErrorCodes}). 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.FIELD) 14 | public @interface JavaOnly { 15 | /** 16 | * This is just here so the annotation is retained at runtime. 17 | */ 18 | String value() default ""; 19 | } 20 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/sbt/tox4j/lint/Findbugs.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j.lint 2 | 3 | import de.johoop.findbugs4sbt.FindBugs._ 4 | import de.johoop.findbugs4sbt._ 5 | import sbt.tox4j.OptionalPlugin 6 | 7 | // scalastyle:off 8 | object Findbugs extends OptionalPlugin { 9 | 10 | object Keys 11 | 12 | override val moduleSettings = findbugsSettings ++ Seq( 13 | findbugsReportType := Some(ReportType.Html), 14 | findbugsExcludeFilters := Some( 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | ) 24 | ) 25 | 26 | } 27 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxSetInfoException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxSetInfoException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * An argument was null. 11 | */ 12 | NULL, 13 | /** 14 | * Information length exceeded maximum permissible size. 15 | */ 16 | TOO_LONG, 17 | } 18 | 19 | public ToxSetInfoException(@NotNull Code code) { 20 | this(code, ""); 21 | } 22 | 23 | public ToxSetInfoException(@NotNull Code code, String message) { 24 | super(code, message); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/callbacks/BitRateStatusCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.callbacks 2 | 3 | /** 4 | * The event is triggered when the network becomes too saturated for current 5 | * bit rates at which point core suggests new bit rates. 6 | */ 7 | trait BitRateStatusCallback[ToxCoreState] { 8 | /** 9 | * @param friendNumber The friend number of the friend for which to set the 10 | * video bit rate. 11 | * @param audioBitRate Suggested maximum audio bit rate in Kb/sec. 12 | * @param videoBitRate Suggested maximum video bit rate in Kb/sec. 13 | */ 14 | def bitRateStatus( 15 | friendNumber: Int, audioBitRate: Int, videoBitRate: Int 16 | )(state: ToxCoreState): ToxCoreState = state 17 | } 18 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/callbacks/AudioReceiveFrameCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.callbacks 2 | 3 | import org.jetbrains.annotations.NotNull 4 | 5 | /** 6 | * Called when an audio frame is received. 7 | */ 8 | trait AudioReceiveFrameCallback[ToxCoreState] { 9 | /** 10 | * @param friendNumber The friend number of the friend who sent an audio frame. 11 | * @param pcm An array of audio samples (sample_count * channels elements). 12 | * @param channels Number of audio channels. 13 | * @param samplingRate Sampling rate used in this frame. 14 | */ 15 | def audioReceiveFrame( 16 | friendNumber: Int, @NotNull pcm: Array[Short], channels: Int, samplingRate: Int 17 | )(state: ToxCoreState): ToxCoreState = state 18 | } 19 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/dhtPacket.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | open Types 3 | 4 | 5 | let unpack ~dht ~buf ~f = 6 | let open Or_error in 7 | let public_key = PublicKey.unpack ~buf in 8 | let nonce = Nonce.unpack ~buf in 9 | 10 | Dht.node_by_key ~dht public_key >>= fun node -> 11 | let channel_key = node.cn_ckey in 12 | Crypto.unpack_encrypted ~channel_key ~nonce buf >>= fun plain -> 13 | 14 | f ~buf:plain >>| fun result -> 15 | node, result 16 | 17 | 18 | let pack ~dht ~buf ~node ~kind ~f = 19 | let channel_key = node.cn_ckey in 20 | let nonce = Nonce.random () in 21 | 22 | Packet.Kind.pack buf kind; 23 | 24 | PublicKey.pack buf dht.dht_pk; 25 | Nonce.pack buf nonce; 26 | 27 | Crypto.pack_encrypted ~channel_key ~nonce ~buf ~f 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendRequestCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import org.jetbrains.annotations.NotNull 4 | 5 | /** 6 | * This event is triggered when a friend request is received. 7 | */ 8 | trait FriendRequestCallback[ToxCoreState] { 9 | /** 10 | * @param publicKey The Public Key of the user who sent the friend request. 11 | * @param timeDelta A delta in seconds between when the message was composed 12 | * and when it is being transmitted. 13 | * @param message The message they sent along with the request. 14 | */ 15 | def friendRequest( 16 | @NotNull publicKey: Array[Byte], timeDelta: Int, @NotNull message: Array[Byte] 17 | )(state: ToxCoreState): ToxCoreState = state 18 | } 19 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/bench/MemoryReport.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.bench 2 | 3 | import org.scalameter.api._ 4 | 5 | /** 6 | * Base class for memory benchmarks. Use the `memory` method at the top level and any other DSL statements inside. Do 7 | * not use `performance of` at the top level, as it will not use [[PerformanceReportBase.defaultConfig]]. 8 | */ 9 | abstract class MemoryReport extends PerformanceReportBase { 10 | 11 | override def measurer: Measurer[Double] = new Executor.Measurer.MemoryFootprint 12 | 13 | object memory { // scalastyle:ignore object.name 14 | def of(modulename: String): Scope = performance of (modulename + " (memory)") config defaultConfig 15 | def of[T](clazz: Class[T]): Scope = of(clazz.getSimpleName) 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/bench/IterateMemoryBench.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.bench 2 | 3 | import im.tox.tox4j.bench.MemoryReport 4 | import im.tox.tox4j.bench.PerformanceReportBase._ 5 | import im.tox.tox4j.core.ToxCore 6 | 7 | final class IterateMemoryBench extends MemoryReport { 8 | 9 | memory of classOf[ToxCore[Unit]] in { 10 | 11 | measure method "iterate" in { 12 | usingTox(iterations1k) in { 13 | case (sz, tox) => 14 | (0 until sz) foreach (_ => tox.iterate(())) 15 | } 16 | } 17 | 18 | measure method "iterationInterval" in { 19 | usingTox(iterations1k) in { 20 | case (sz, tox) => 21 | (0 until sz) foreach (_ => tox.iterationInterval) 22 | } 23 | } 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/exceptions/ToxKilledExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.exceptions 2 | 3 | import im.tox.tox4j.core.ToxCoreFactory.withTox 4 | import org.scalatest.FunSuite 5 | 6 | final class ToxKilledExceptionTest extends FunSuite { 7 | 8 | test("UseAfterCloseInOrder") { 9 | intercept[ToxKilledException] { 10 | withTox { tox1 => 11 | withTox { tox2 => 12 | tox1.close() 13 | tox1.iterationInterval 14 | } 15 | } 16 | } 17 | } 18 | 19 | test("UseAfterCloseReverseOrder") { 20 | intercept[ToxKilledException] { 21 | withTox { tox1 => 22 | withTox { tox2 => 23 | tox2.close() 24 | tox2.iterationInterval 25 | } 26 | } 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/sbt/tox4j/logic/jni/BuildTool.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j.logic.jni 2 | 3 | import sbt._ 4 | 5 | final case class BuildTool( 6 | name: String, 7 | command: String 8 | ) 9 | 10 | object BuildTool { 11 | 12 | val Ninja = BuildTool("Ninja", "ninja") 13 | val Make = BuildTool("Unix Makefiles", "make") 14 | 15 | val tool = { 16 | Seq(Ninja, Make).foldLeft[Option[BuildTool]](None) { (found, next) => 17 | found match { 18 | case Some(_) => found 19 | case None => 20 | try { 21 | Seq(next.command, "--version") !< Configure.configLog 22 | Some(next) 23 | } catch { 24 | case _: java.io.IOException => None 25 | } 26 | } 27 | } getOrElse Make 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/nodesRequest.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | open Types 3 | 4 | 5 | let kind = Packet.Kind.NodesRequest 6 | type t = Packet.Data.nodes_request = { 7 | key : PublicKey.t; 8 | ping_id : int64; 9 | } 10 | 11 | 12 | let wrap decoded = 13 | Packet.Data.NodesRequest decoded 14 | 15 | 16 | let unpack ~dht ~buf = 17 | DhtPacket.unpack ~dht ~buf 18 | ~f:( 19 | fun ~buf -> 20 | let key = PublicKey.unpack ~buf in 21 | let ping_id = Message.Consume.int64_t_be buf in 22 | Or_error.return { key; ping_id } 23 | ) 24 | 25 | 26 | let pack ~dht ~buf ~node ~packet = 27 | DhtPacket.pack ~dht ~buf ~node ~kind ~f:( 28 | fun ~buf -> 29 | PublicKey.pack ~buf packet.key; 30 | Message.Fill.int64_t_be buf packet.ping_id; 31 | ) 32 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/domain/Friend.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.domain 2 | 3 | import java.io.Serializable 4 | 5 | import im.tox.tox4j.core.ToxCoreConstants 6 | import im.tox.tox4j.core.enums.{ToxConnection, ToxUserStatus} 7 | 8 | final class Friend(val publicKey: Array[Byte]) extends Serializable { 9 | require(publicKey.length == ToxCoreConstants.PublicKeySize) 10 | 11 | var name: String = "" 12 | @transient 13 | var connectionStatus: ToxConnection = null 14 | @transient 15 | var status: ToxUserStatus = null 16 | var statusMessage: String = null 17 | @transient 18 | var typing: Boolean = false 19 | 20 | override def toString: String = { 21 | s"Friend ($name, $connectionStatus, $status, $statusMessage)${if (typing) " [typing]" else ""}" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/inetAddr.mli: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | 4 | type ipv4 5 | type ipv6 6 | 7 | type 'kind address = private string 8 | 9 | type t = 10 | | IPv4 of ipv4 address 11 | | IPv6 of ipv6 address 12 | 13 | val ipv4_size : int 14 | val ipv6_size : int 15 | 16 | val ipv4_of_string : string -> ipv4 address option 17 | val ipv6_of_string : string -> ipv6 address option 18 | 19 | val read_ipv4 : (Message.plain, ipv4 address) Message.Consume.t 20 | val read_ipv6 : (Message.plain, ipv6 address) Message.Consume.t 21 | 22 | val write_ipv4 : (Message.plain, ipv4 address) Message.Fill.t 23 | val write_ipv6 : (Message.plain, ipv6 address) Message.Fill.t 24 | 25 | val ipv4_to_string : ipv4 address -> string 26 | val ipv6_to_string : ipv6 address -> string 27 | 28 | val to_string : t -> string 29 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendByPublicKeyException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFriendByPublicKeyException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * No friend with the given Public Key exists on the friend list. 11 | */ 12 | NOT_FOUND, 13 | /** 14 | * An argument was null. 15 | */ 16 | NULL, 17 | } 18 | 19 | public ToxFriendByPublicKeyException(@NotNull Code code) { 20 | this(code, ""); 21 | } 22 | 23 | public ToxFriendByPublicKeyException(@NotNull Code code, String message) { 24 | super(code, message); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/util/logging.cpp: -------------------------------------------------------------------------------- 1 | #include "util/logging.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | std::size_t scope_counter::scope; 9 | 10 | std::ostream & 11 | scope_indent (std::ostream &os, int line) 12 | { 13 | for (std::size_t i = 0; i < scope_counter::scope - (line >= 1000); i++) 14 | os << ' '; 15 | return os; 16 | } 17 | 18 | 19 | void 20 | output_hex (std::ostream &os, uint8_t const *data, size_t length) 21 | { 22 | os << '['; 23 | for (size_t i = 0; i < length; i++) 24 | os << format ("%02x", data[i]); 25 | os << ']'; 26 | } 27 | 28 | 29 | std::ostream & 30 | operator << (std::ostream &os, formatter const &fmt) 31 | { 32 | std::copy (fmt.text_.cbegin (), fmt.text_.cend (), std::ostream_iterator (os)); 33 | return os; 34 | } 35 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/av/bench/AvProfiling.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.bench 2 | 3 | import im.tox.tox4j.core.options.ToxOptions 4 | import im.tox.tox4j.impl.jni.{ToxAvImpl, ToxCoreImpl} 5 | 6 | import scala.util.Random 7 | 8 | object AvProfiling extends App { 9 | 10 | val tox = new ToxCoreImpl[Unit](ToxOptions()) 11 | val toxAv = new ToxAvImpl[Unit](tox) 12 | 13 | val friendNumber = 1 14 | val pcm = Array.ofDim[Short](200) 15 | 16 | val random = new Random 17 | pcm.indices.foreach { i => 18 | pcm(i) = random.nextInt().toShort 19 | } 20 | 21 | val channels = 1 22 | val samplingRate = 1 23 | 24 | while (true) { 25 | toxAv.invokeAudioReceiveFrame(friendNumber, pcm, channels, samplingRate) 26 | toxAv.iterate(()) 27 | } 28 | 29 | toxAv.close() 30 | tox.close() 31 | 32 | } 33 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/exceptions/ToxFriendDeleteExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions 2 | 3 | import im.tox.tox4j.testing.ToxTestMixin 4 | import org.scalatest.FunSuite 5 | 6 | final class ToxFriendDeleteExceptionTest extends FunSuite with ToxTestMixin { 7 | 8 | test("DeleteFriendTwice") { 9 | interceptWithTox(ToxFriendDeleteException.Code.FRIEND_NOT_FOUND) { tox => 10 | addFriends(tox, 4) 11 | assert(tox.getFriendList sameElements Array(0, 1, 2, 3, 4)) 12 | tox.deleteFriend(2) 13 | assert(tox.getFriendList sameElements Array(0, 1, 3, 4)) 14 | tox.deleteFriend(2) 15 | } 16 | } 17 | 18 | test("DeleteNonExistentFriend") { 19 | interceptWithTox(ToxFriendDeleteException.Code.FRIEND_NOT_FOUND)( 20 | _.deleteFriend(1) 21 | ) 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /projects/macros/build.sbt: -------------------------------------------------------------------------------- 1 | organization := "im.tox" 2 | name := "macros" 3 | scalaVersion := "2.11.7" 4 | 5 | // Build dependencies. 6 | libraryDependencies ++= Seq( 7 | "org.scala-lang" % "scala-compiler" % scalaVersion.value, 8 | "org.scalaz" %% "scalaz-core" % "7.2.0-M1" 9 | ) 10 | 11 | // Test dependencies. 12 | libraryDependencies ++= Seq( 13 | "org.scalatest" %% "scalatest" % "2.2.4" 14 | ) map (_ % Test) 15 | 16 | // TODO(iphydf): scoverage doesn't instrument the macro implementation, causing 17 | // 0% coverage. In fact, we have 100% coverage except for the @compileTimeOnly 18 | // implicit conversion. 19 | ScoverageSbtPlugin.ScoverageKeys.coverageMinimum := 0 20 | 21 | // Enable the plugins we want. 22 | sbt.tox4j.lint.Checkstyle.moduleSettings 23 | sbt.tox4j.lint.Scalastyle.moduleSettings 24 | sbt.tox4j.CodeFormat.projectSettings 25 | -------------------------------------------------------------------------------- /projects/macros/src/test/scala/im/tox/tox4j/OptimisedIdOpsTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import im.tox.tox4j.OptimisedIdOps._ 4 | import org.scalatest.FunSuite 5 | 6 | final class OptimisedIdOpsTest extends FunSuite { 7 | 8 | private final class Foo { 9 | def a[A <: Int](int: A): Int = int + 1 10 | def b(int: Int): Int = int + 2 11 | def c(int: Int): Int = int + 3 12 | 13 | def test(): Unit = { 14 | val piped = 1 |> a |> b |> c 15 | val called = c(b(a[Int](1))) 16 | assert(piped == called) 17 | } 18 | } 19 | 20 | test("|>") { 21 | new Foo().test() 22 | } 23 | 24 | test("lambdas") { 25 | val x = 1 |> ((x: Int) => x + 1) 26 | assert(x == 2) 27 | } 28 | 29 | test("named lambdas") { 30 | val lambda = (x: Int) => x + 1 31 | val x = 1 |> lambda 32 | assert(x == 2) 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/enums/ToxFileControl.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.enums; 2 | 3 | public enum ToxFileControl { 4 | /** 5 | * Sent by the receiving side to accept a file send request. Also sent after a 6 | * {@link #PAUSE} command to continue sending or receiving. 7 | */ 8 | RESUME, 9 | /** 10 | * Sent by clients to pause the file transfer. The initial state of a file 11 | * transfer is always paused on the receiving side and running on the sending 12 | * side. If both the sending and receiving side pause the transfer, then both 13 | * need to send {@link #RESUME} for the transfer to resume. 14 | */ 15 | PAUSE, 16 | /** 17 | * Sent by the receiving side to reject a file send request before any other 18 | * commands are sent. Also sent by either side to terminate a file transfer. 19 | */ 20 | CANCEL, 21 | } 22 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/ToxEventListener.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | trait ToxEventListener[ToxCoreState] 4 | extends SelfConnectionStatusCallback[ToxCoreState] 5 | with FileRecvControlCallback[ToxCoreState] 6 | with FileRecvCallback[ToxCoreState] 7 | with FileRecvChunkCallback[ToxCoreState] 8 | with FileChunkRequestCallback[ToxCoreState] 9 | with FriendConnectionStatusCallback[ToxCoreState] 10 | with FriendMessageCallback[ToxCoreState] 11 | with FriendNameCallback[ToxCoreState] 12 | with FriendRequestCallback[ToxCoreState] 13 | with FriendStatusCallback[ToxCoreState] 14 | with FriendStatusMessageCallback[ToxCoreState] 15 | with FriendTypingCallback[ToxCoreState] 16 | with FriendLosslessPacketCallback[ToxCoreState] 17 | with FriendLossyPacketCallback[ToxCoreState] 18 | with FriendReadReceiptCallback[ToxCoreState] 19 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFileGetException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFileGetException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The friendNumber passed did not designate a valid friend. 11 | */ 12 | FRIEND_NOT_FOUND, 13 | /** 14 | * No file transfer with the given file number was found for the given friend. 15 | */ 16 | NOT_FOUND, 17 | /** 18 | * An argument was null. 19 | */ 20 | NULL, 21 | } 22 | 23 | public ToxFileGetException(@NotNull Code code) { 24 | this(code, ""); 25 | } 26 | 27 | public ToxFileGetException(@NotNull Code code, String message) { 28 | super(code, message); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/callbacks/CallStateCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.callbacks 2 | 3 | import java.util 4 | 5 | import im.tox.tox4j.av.enums.ToxavFriendCallState 6 | import org.jetbrains.annotations.NotNull 7 | 8 | /** 9 | * Called when the call state changes. 10 | */ 11 | trait CallStateCallback[ToxCoreState] { 12 | /** 13 | * @param friendNumber The friend number this call state change is for. 14 | * @param callState A set of ToxCallState values comprising the new call state. 15 | * Although this is a Collection (therefore might actually be a List), this is 16 | * effectively a Set. Any [[ToxavFriendCallState]] value is contained exactly 0 or 1 times. 17 | */ 18 | def callState( 19 | friendNumber: Int, @NotNull callState: util.Collection[ToxavFriendCallState] 20 | )(state: ToxCoreState): ToxCoreState = state 21 | } 22 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/crypto/ToxCryptoConstants.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.crypto 2 | 3 | object ToxCryptoConstants { 4 | 5 | /** 6 | * Length of salt in bytes. 7 | */ 8 | final val SaltLength = 32 9 | 10 | /** 11 | * The number of bytes in a serialised [[ToxCrypto.PassKey]] without salt. 12 | * The serialised size is [[KeyLength]] + [[SaltLength]]. 13 | */ 14 | final val KeyLength = 32 15 | 16 | /** 17 | * Number of bytes added to any encrypted data. 18 | */ 19 | final val EncryptionExtraLength = 80 20 | 21 | /** 22 | * The number of bytes in a hash generated by tox_hash. 23 | */ 24 | final val HashLength = 32 25 | 26 | final val PublicKeyLength = 32 27 | final val SecretKeyLength = 32 28 | final val SharedKeyLength = 32 29 | final val NonceLength = 24 30 | 31 | final val ZeroBytes = 32 32 | final val BoxZeroBytes = 16 33 | 34 | } 35 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/FriendConnectionStatusCallbackTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxConnection 4 | import im.tox.tox4j.testing.autotest.AliceBobTest 5 | 6 | final class FriendConnectionStatusCallbackTest extends AliceBobTest { 7 | 8 | override type State = Unit 9 | override def initialState: State = () 10 | 11 | protected override def newChatClient(name: String, expectedFriendName: String) = new ChatClient(name, expectedFriendName) { 12 | 13 | override def friendConnectionStatus(friendNumber: Int, connectionStatus: ToxConnection)(state: ChatState): ChatState = { 14 | super.friendConnectionStatus(friendNumber, connectionStatus)(state) 15 | if (connectionStatus != ToxConnection.NONE) { 16 | state.finish 17 | } else { 18 | state 19 | } 20 | } 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Tox4j contributors 2 | 3 | This is a list of people who have directly contributed code to the repository. 4 | Countless others have been a major help in reviewing and contributing ideas, 5 | but this document mainly serves as a record for code ownership, so we don't 6 | list those here. 7 | 8 | # Core tox4j-team 9 | 10 | The people listed here own the source code to Tox4j. The rights assigned to 11 | tox4j-team by contributors are owned by this group. 12 | 13 | - Simon "sonOfRa" Levermann 14 | - Iphigenia "iphydf" D. 15 | 16 | # Contributors 17 | 18 | These people have contributed code to the repository and have signed the 19 | Contributor License Agreement. If you are a future contributor, please add 20 | your name and email address here. 21 | 22 | - Sebastian "Flakebi" Neubauer 23 | - Xinyue "SilviaBear" Xu 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/SelfConnectionStatusCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.ToxCore 4 | import im.tox.tox4j.core.enums.ToxConnection 5 | import org.jetbrains.annotations.NotNull 6 | 7 | /** 8 | * This event is triggered whenever there is a change in the DHT connection 9 | * state. When disconnected, a client may choose to call [[ToxCore.bootstrap]] again, to 10 | * reconnect to the DHT. Note that this state may frequently change for short 11 | * amounts of time. Clients should therefore not immediately bootstrap on 12 | * receiving a disconnect. 13 | */ 14 | trait SelfConnectionStatusCallback[ToxCoreState] { 15 | /** 16 | * @param connectionStatus The new connection status. 17 | */ 18 | def selfConnectionStatus( 19 | @NotNull connectionStatus: ToxConnection 20 | )(state: ToxCoreState): ToxCoreState = state 21 | } 22 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxAv/generated/natives.h: -------------------------------------------------------------------------------- 1 | // im.tox.tox4j.impl.jni.ToxAvJni 2 | JAVA_METHOD_REF (toxavAnswer) 3 | CXX_FUNCTION_REF (toxav_answer) 4 | JAVA_METHOD_REF (toxavAudioSendFrame) 5 | CXX_FUNCTION_REF (toxav_audio_send_frame) 6 | JAVA_METHOD_REF (toxavBitRateSet) 7 | CXX_FUNCTION_REF (toxav_bit_rate_set) 8 | JAVA_METHOD_REF (toxavCall) 9 | CXX_FUNCTION_REF (toxav_call) 10 | JAVA_METHOD_REF (toxavCallControl) 11 | CXX_FUNCTION_REF (toxav_call_control) 12 | JAVA_METHOD_REF (toxavFinalize) 13 | CXX_FUNCTION_REF (toxav_finalize) 14 | JAVA_METHOD_REF (toxavIterate) 15 | CXX_FUNCTION_REF (toxav_iterate) 16 | JAVA_METHOD_REF (toxavIterationInterval) 17 | CXX_FUNCTION_REF (toxav_iteration_interval) 18 | JAVA_METHOD_REF (toxavKill) 19 | CXX_FUNCTION_REF (toxav_kill) 20 | JAVA_METHOD_REF (toxavNew) 21 | CXX_FUNCTION_REF (toxav_new) 22 | JAVA_METHOD_REF (toxavVideoSendFrame) 23 | CXX_FUNCTION_REF (toxav_video_send_frame) 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendConnectionStatusCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxConnection 4 | import org.jetbrains.annotations.NotNull 5 | 6 | /** 7 | * This event is triggered when a friend goes offline after having been online, 8 | * when a friend goes online, or when the connection type (TCP/UDP) changes. 9 | * 10 | * This callback is not called when adding friends. It is assumed that when 11 | * adding friends, their connection status is initially offline. 12 | */ 13 | trait FriendConnectionStatusCallback[ToxCoreState] { 14 | /** 15 | * @param friendNumber The friend number of the friend whose connection status changed. 16 | * @param connectionStatus The new connection status. 17 | */ 18 | def friendConnectionStatus( 19 | friendNumber: Int, @NotNull connectionStatus: ToxConnection 20 | )(state: ToxCoreState): ToxCoreState = state 21 | } 22 | -------------------------------------------------------------------------------- /projects/build-basic/src/test/scala/org/scalastyle/scalariform/tox4j/ForBraceCheckerTest.scala: -------------------------------------------------------------------------------- 1 | package org.scalastyle.scalariform.tox4j 2 | 3 | import org.scalastyle.scalariform.CheckerTest 4 | 5 | final class ForBraceCheckerTest extends CheckerTest(new ForBraceChecker) { 6 | 7 | test("flag braces on the same line") { 8 | assertErrors(1, """ 9 | class Foo { 10 | for !!{ t <- List(1,2,3) } yield t 11 | }""") 12 | } 13 | 14 | test("do not flag parentheses on the same line") { 15 | assertErrors(0, """ 16 | class Foo { 17 | for (t <- List(1,2,3)) yield t 18 | }""") 19 | } 20 | 21 | test("flag parentheses on a separate line") { 22 | assertErrors(1, """ 23 | class Foo { 24 | for !!( 25 | t <- List(1,2,3) 26 | ) yield t 27 | }""") 28 | } 29 | 30 | test("do not flag braces on a separate line") { 31 | assertErrors(0, """ 32 | class Foo { 33 | for { 34 | t <- List(1,2,3) 35 | } yield t 36 | }""") 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FileRecvControlCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxFileControl 4 | import org.jetbrains.annotations.NotNull 5 | 6 | /** 7 | * This event is triggered when a file control command is received from a 8 | * friend. 9 | */ 10 | trait FileRecvControlCallback[ToxCoreState] { 11 | /** 12 | * When receiving [[ToxFileControl.CANCEL]], the client should release the 13 | * resources associated with the file number and consider the transfer failed. 14 | * 15 | * @param friendNumber The friend number of the friend who is sending the file. 16 | * @param fileNumber The friend-specific file number the data received is associated with. 17 | * @param control The file control command received. 18 | */ 19 | def fileRecvControl( 20 | friendNumber: Int, fileNumber: Int, @NotNull control: ToxFileControl 21 | )(state: ToxCoreState): ToxCoreState = state 22 | } 23 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/enums/ToxConnection.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.enums; 2 | 3 | /** 4 | * Protocols that can be used to connect to the network or friends. 5 | */ 6 | public enum ToxConnection { 7 | /** 8 | * There is no connection. This instance, or the friend the state change is 9 | * about, is now offline. 10 | */ 11 | NONE, 12 | /** 13 | * A TCP connection has been established. For the own instance, this means it 14 | * is connected through a TCP relay, only. For a friend, this means that the 15 | * connection to that particular friend goes through a TCP relay. 16 | */ 17 | TCP, 18 | /** 19 | * A UDP connection has been established. For the own instance, this means it 20 | * is able to send UDP packets to DHT nodes, but may still be connected to 21 | * a TCP relay. For a friend, this means that the connection to that 22 | * particular friend was built using direct UDP packets. 23 | */ 24 | UDP, 25 | } 26 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/nodesResponse.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | open Types 3 | 4 | 5 | let kind = Packet.Kind.NodesResponse 6 | type t = Packet.Data.nodes_response = { 7 | nodes : node list; 8 | ping_id : int64; 9 | } 10 | 11 | 12 | let wrap decoded = 13 | Packet.Data.NodesResponse decoded 14 | 15 | 16 | let unpack ~dht ~buf = 17 | let open Or_error in 18 | 19 | DhtPacket.unpack ~dht ~buf 20 | ~f:( 21 | fun ~buf -> 22 | Packet.unpack_repeated ~buf ~size:Message.Consume.uint8 ~f:Node.unpack 23 | >>| fun nodes -> 24 | let ping_id = Message.Consume.int64_t_be buf in 25 | { 26 | nodes; 27 | ping_id; 28 | } 29 | ) 30 | 31 | 32 | let pack ~dht ~buf ~node ~packet = 33 | DhtPacket.pack ~dht ~buf ~node ~kind ~f:( 34 | fun ~buf -> 35 | Packet.pack_repeated 36 | ~buf ~size:Message.Fill.uint8 packet.nodes ~f:Node.pack; 37 | Message.Fill.int64_t_be buf packet.ping_id; 38 | ) 39 | -------------------------------------------------------------------------------- /projects/build-extra/src/main/scala/sbt/tox4j/Coverage.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j 2 | 3 | import sbt.PluginTrigger 4 | import scoverage.ScoverageSbtPlugin.ScoverageKeys._ 5 | 6 | /** 7 | * Default settings object for coverage. Requires 100% coverage on everything except generated protobuf code. 8 | */ 9 | object Coverage extends sbt.AutoPlugin { 10 | 11 | /** 12 | * This plugin is activated when all required plugins are present. 13 | * @return [[allRequirements]]. 14 | */ 15 | override def trigger: PluginTrigger = allRequirements 16 | 17 | /** 18 | * Require 100% coverage. Fail the test if coverage is not met. 19 | * @return A sequence of Settings. 20 | */ 21 | override def projectSettings: Seq[sbt.Setting[_]] = Seq( 22 | // Require 100% test coverage. 23 | coverageMinimum := 100, 24 | coverageFailOnMinimum := true, 25 | 26 | // Ignore generated proto sources in coverage. 27 | coverageExcludedPackages := ".*\\.proto\\..*" 28 | ) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCore/ToxCore.cpp: -------------------------------------------------------------------------------- 1 | #include "ToxCore.h" 2 | 3 | #ifdef TOX_VERSION_MAJOR 4 | 5 | using namespace core; 6 | 7 | #include "generated/impls.h" 8 | 9 | void 10 | reference_symbols_core () 11 | { 12 | int tox_finalize; // For Java only. 13 | 14 | #define JAVA_METHOD_REF(NAME) unused (JAVA_METHOD_NAME (NAME)); 15 | #define CXX_FUNCTION_REF(NAME) unused (NAME); 16 | #include "generated/natives.h" 17 | #undef CXX_FUNCTION_REF 18 | #undef JAVA_METHOD_REF 19 | } 20 | 21 | #define TOX_MAX_HOSTNAME_LENGTH 255 22 | #define TOX_DEFAULT_PROXY_PORT 8080 23 | #define TOX_DEFAULT_TCP_PORT 0 24 | #define TOX_DEFAULT_START_PORT 33445 25 | #define TOX_DEFAULT_END_PORT (TOX_DEFAULT_START_PORT + 100) 26 | #include "generated/constants.h" 27 | 28 | ToxInstances> core::instances; 29 | 30 | template<> extern char const *const module_name = "core"; 31 | template<> extern char const *const exn_prefix = ""; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/node.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | 4 | let unpack_after_proto ~buf n_proto n_addr = 5 | let open Or_error in 6 | Port.unpack buf >>= fun n_port -> 7 | let n_key = PublicKey.unpack ~buf in 8 | 9 | return 10 | Types.({ 11 | n_proto; 12 | n_addr; 13 | n_port; 14 | n_key; 15 | }) 16 | 17 | 18 | let unpack ~buf = 19 | let protocol = Message.Consume.uint8 buf in 20 | 21 | let n_proto = 22 | match protocol lsr 7 with 23 | | 0 -> Protocol.UDP 24 | | 1 -> Protocol.TCP 25 | | _ -> assert false 26 | in 27 | 28 | match protocol land 0x7f with 29 | | 0b0010 -> 30 | unpack_after_proto ~buf n_proto 31 | (InetAddr.IPv4 (InetAddr.read_ipv4 buf)) 32 | | 0b1010 -> 33 | unpack_after_proto ~buf n_proto 34 | (InetAddr.IPv6 (InetAddr.read_ipv6 buf)) 35 | | _ -> 36 | Or_error.of_exn (Packet.Format_error "Node:protocol") 37 | 38 | 39 | let pack ~buf node = 40 | assert false 41 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCrypto/ToxCrypto.cpp: -------------------------------------------------------------------------------- 1 | #include "ToxCrypto.h" 2 | 3 | #include 4 | #include 5 | #define TOX_PASS_HASH_LENGTH TOX_HASH_LENGTH 6 | #define TOX_PASS_PUBLIC_KEY_LENGTH crypto_box_PUBLICKEYBYTES 7 | #define TOX_PASS_SECRET_KEY_LENGTH crypto_box_SECRETKEYBYTES 8 | #define TOX_PASS_SHARED_KEY_LENGTH crypto_box_BEFORENMBYTES 9 | #define TOX_PASS_NONCE_LENGTH crypto_box_NONCEBYTES 10 | #define TOX_PASS_ZERO_BYTES crypto_box_ZEROBYTES 11 | #define TOX_PASS_BOX_ZERO_BYTES crypto_box_BOXZEROBYTES 12 | #include "generated/constants.h" 13 | 14 | template<> extern char const *const module_name = "crypto"; 15 | template<> extern char const *const exn_prefix = ""; 16 | 17 | void 18 | reference_symbols_crypto () 19 | { 20 | #define JAVA_METHOD_REF(NAME) unused (JAVA_METHOD_NAME (NAME)); 21 | #define CXX_FUNCTION_REF(NAME) unused (NAME); 22 | #include "generated/natives.h" 23 | #undef CXX_FUNCTION_REF 24 | #undef JAVA_METHOD_REF 25 | } 26 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCore/generated/impls.h: -------------------------------------------------------------------------------- 1 | // im.tox.tox4j.impl.jni.ToxCoreJni 2 | 3 | JAVA_METHOD (jint, toxIterationInterval, 4 | jint instanceNumber) 5 | { 6 | return instances.with_instance_noerr (env, instanceNumber, tox_iteration_interval); 7 | } 8 | 9 | JAVA_METHOD (jint, toxSelfGetStatus, 10 | jint instanceNumber) 11 | { 12 | return instances.with_instance_noerr (env, instanceNumber, tox_self_get_status); 13 | } 14 | 15 | JAVA_METHOD (void, toxSelfSetNospam, 16 | jint instanceNumber, jint nospam) 17 | { 18 | return instances.with_instance_noerr (env, instanceNumber, tox_self_set_nospam, nospam); 19 | } 20 | 21 | JAVA_METHOD (jboolean, toxFriendExists, 22 | jint instanceNumber, jint friendNumber) 23 | { 24 | return instances.with_instance_noerr (env, instanceNumber, tox_friend_exists, friendNumber); 25 | } 26 | 27 | JAVA_METHOD (jint, toxSelfGetNospam, 28 | jint instanceNumber) 29 | { 30 | return instances.with_instance_noerr (env, instanceNumber, tox_self_get_nospam); 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://jenkins.libtoxcore.so/job/Sync%20Tox4j/badge/icon)](https://jenkins.libtoxcore.so/job/Sync%20Tox4j/) 2 | [![Travis Build Status](https://api.travis-ci.org/tox4j/tox4j.svg)](https://travis-ci.org/tox4j/tox4j) 3 | [![Coverage Status](https://coveralls.io/repos/tox4j/tox4j/badge.svg?branch=auto)](https://coveralls.io/r/tox4j/tox4j?branch=auto) 4 | 5 | # Tox4j 6 | 7 | Combined repository for several Tox4j projects. These can be found in the 8 | `projects` directory and currently include: 9 | 10 | - build-basic: A collection of SBT plugins used by all Tox4j projects. 11 | - build-extra: Additional SBT plugins that require a specific version of Scala. 12 | - linters: Extra WartRemover linters with knowledge of our standards. 13 | - tox4j: The core and high level client libraries. 14 | 15 | 16 | ## Contributing 17 | 18 | We're evaluating Homu and Highfive at the moment to manage our review process. 19 | Just open Pull Requests, the bots and the reviewer will guide you through the 20 | process! 21 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/crypto/exceptions/ToxEncryptionException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.crypto.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxEncryptionException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The encryption itself failed. 11 | */ 12 | FAILED, 13 | /** 14 | * The crypto lib was unable to derive a key from the given passphrase, 15 | * which is usually a lack of memory issue. The functions accepting keys 16 | * do not produce this error. 17 | */ 18 | KEY_DERIVATION_FAILED, 19 | /** 20 | * The key or input data was null or empty. 21 | */ 22 | NULL, 23 | } 24 | 25 | public ToxEncryptionException(@NotNull Code code) { 26 | this(code, ""); 27 | } 28 | 29 | public ToxEncryptionException(@NotNull Code code, String message) { 30 | super(code, message); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCrypto/generated/constants.h: -------------------------------------------------------------------------------- 1 | // im.tox.tox4j.crypto.ToxCryptoConstants$ 2 | void 3 | checkToxCryptoConstants () 4 | { 5 | static_assert (TOX_PASS_BOX_ZERO_BYTES == 16, "Java constant out of sync with C"); 6 | static_assert (TOX_PASS_ENCRYPTION_EXTRA_LENGTH == 80, "Java constant out of sync with C"); 7 | static_assert (TOX_PASS_HASH_LENGTH == 32, "Java constant out of sync with C"); 8 | static_assert (TOX_PASS_KEY_LENGTH == 32, "Java constant out of sync with C"); 9 | static_assert (TOX_PASS_NONCE_LENGTH == 24, "Java constant out of sync with C"); 10 | static_assert (TOX_PASS_PUBLIC_KEY_LENGTH == 32, "Java constant out of sync with C"); 11 | static_assert (TOX_PASS_SALT_LENGTH == 32, "Java constant out of sync with C"); 12 | static_assert (TOX_PASS_SECRET_KEY_LENGTH == 32, "Java constant out of sync with C"); 13 | static_assert (TOX_PASS_SHARED_KEY_LENGTH == 32, "Java constant out of sync with C"); 14 | static_assert (TOX_PASS_ZERO_BYTES == 32, "Java constant out of sync with C"); 15 | } 16 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/events/BootstrapButtonOnAction.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.events 2 | 3 | import java.awt.event.{ActionEvent, ActionListener} 4 | import javax.swing._ 5 | 6 | import im.tox.gui.MainView 7 | import im.tox.tox4j.ToxCoreTestBase.parsePublicKey 8 | import im.tox.tox4j.core.exceptions.ToxBootstrapException 9 | 10 | final class BootstrapButtonOnAction(toxGui: MainView) extends ActionListener { 11 | 12 | def actionPerformed(event: ActionEvent): Unit = { 13 | try { 14 | Seq( 15 | toxGui.tox.addTcpRelay _, 16 | toxGui.tox.bootstrap _ 17 | ) foreach (_( 18 | toxGui.bootstrapHost.getText, 19 | toxGui.bootstrapPort.getText.toInt, 20 | parsePublicKey(toxGui.bootstrapKey.getText.trim) 21 | )) 22 | } catch { 23 | case e: ToxBootstrapException => 24 | toxGui.addMessage("Bootstrap failed: ", e.code) 25 | case e: Throwable => 26 | JOptionPane.showMessageDialog(toxGui, MainView.printExn(e)) 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/bench/BenchWip.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.bench 2 | 3 | import im.tox.tox4j.bench.PerformanceReportBase._ 4 | import im.tox.tox4j.bench.{Confidence, TimingReport} 5 | import im.tox.tox4j.core.ToxCore 6 | 7 | /** 8 | * Work in progress benchmarks. 9 | */ 10 | final class BenchWip extends TimingReport { 11 | 12 | protected override def confidence = Confidence.normal 13 | 14 | timing of classOf[ToxCore[Unit]] in { 15 | 16 | measure method "iterate+friends" in { 17 | using(iterations1k, toxWithFriends1k) in { 18 | case (sz, tox) => 19 | (0 until sz) foreach (_ => tox.iterate(())) 20 | } 21 | } 22 | 23 | } 24 | 25 | /** 26 | * Benchmarks we're not currently working on. 27 | */ 28 | object HoldingPen { 29 | 30 | measure method "iterationInterval" in { 31 | usingTox(iterations1k) in { 32 | case (sz, tox) => 33 | (0 until sz) foreach (_ => tox.iterationInterval) 34 | } 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/exceptions/ToxFileSendExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions 2 | 3 | import im.tox.tox4j.core.ToxCoreConstants 4 | import im.tox.tox4j.core.enums.ToxFileKind 5 | import im.tox.tox4j.testing.ToxTestMixin 6 | import org.scalatest.FunSuite 7 | 8 | final class ToxFileSendExceptionTest extends FunSuite with ToxTestMixin { 9 | 10 | test("FileSendNotConnected") { 11 | interceptWithTox(ToxFileSendException.Code.FRIEND_NOT_CONNECTED)( 12 | _.fileSend(0, ToxFileKind.DATA, 123, null, "filename".getBytes) 13 | ) 14 | } 15 | 16 | test("FileSendNotFound") { 17 | interceptWithTox(ToxFileSendException.Code.FRIEND_NOT_FOUND)( 18 | _.fileSend(1, ToxFileKind.DATA, 123, null, "filename".getBytes) 19 | ) 20 | } 21 | 22 | test("FileSendNameTooLong") { 23 | interceptWithTox(ToxFileSendException.Code.NAME_TOO_LONG)( 24 | _.fileSend(0, ToxFileKind.DATA, 123, null, Array.ofDim[Byte](ToxCoreConstants.MaxFilenameLength + 1)) 25 | ) 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tools/git-install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -ex 4 | 5 | PREFIX=$1 6 | BASEURL=$2 7 | REPO=$3 8 | BRANCH=$4 9 | shift 4 10 | 11 | TMPDIR=/tmp/git-install-$$ 12 | 13 | mkdir -p $PREFIX 14 | mkdir -p $TMPDIR 15 | 16 | cd $TMPDIR 17 | git clone --depth=1 --branch="$BRANCH" $BASEURL/$REPO.git \ 18 | || git clone $BASEURL/$REPO.git 19 | cd $REPO 20 | 21 | git checkout $BRANCH 22 | git rev-parse HEAD > $REPO.HEAD 23 | if diff "$PREFIX/$REPO.HEAD" $REPO.HEAD; then 24 | rm -rf $TMPDIR 25 | exit 26 | fi 27 | 28 | mv $REPO.HEAD "$PREFIX" 29 | 30 | # Generate autotools stuff. 31 | if [ ! -f configure ]; then 32 | ./autogen.sh --prefix="$PREFIX" "$@" 33 | fi 34 | 35 | # If autogen.sh didn't also run configure, 36 | if [ ! -f config.log ]; then 37 | # we have a vpath build. 38 | mkdir -p _build 39 | cd _build 40 | # Run configure once. 41 | if [ ! -f config.log ]; then 42 | ../configure --prefix="$PREFIX" "$@" 43 | fi 44 | fi 45 | 46 | # Then build and install. 47 | make -j4 48 | make install 49 | 50 | rm -rf $TMPDIR 51 | 52 | # vim:sw=2 53 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/domain/FileTransferOutgoing.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.domain 2 | 3 | import java.io.{File, FileNotFoundException, IOException, RandomAccessFile} 4 | 5 | final class FileTransferOutgoing(file: File) extends FileTransfer(file) { 6 | private var input: RandomAccessFile = null 7 | 8 | @throws[FileNotFoundException] 9 | def resume(): Unit = { 10 | input = new RandomAccessFile(file, "r") 11 | } 12 | 13 | @throws[IOException] 14 | def read(position: Long, length: Int): Array[Byte] = { 15 | input.seek(position) 16 | 17 | val data = Array.ofDim[Byte](length) 18 | val readLength = input.read(data) 19 | 20 | if (data.length > readLength) { 21 | data.slice(0, readLength) 22 | } else { 23 | data 24 | } 25 | } 26 | 27 | @throws[IOException] 28 | def close(): Unit = { 29 | input.close() 30 | } 31 | 32 | @throws[IOException] 33 | def write(position: Long, data: Array[Byte]): Unit = { 34 | throw new IOException("Cannot write to outgoing file") 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/exceptions/ToxExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.exceptions 2 | 3 | import im.tox.tox4j.core.exceptions.ToxBootstrapException 4 | import org.scalatest.FlatSpec 5 | import org.scalatest.prop.PropertyChecks 6 | 7 | final class ToxExceptionTest extends FlatSpec with PropertyChecks { 8 | 9 | "getMessage" should "contain the error code name" in { 10 | ToxBootstrapException.Code.values().foreach { code => 11 | val exn = new ToxBootstrapException(code) 12 | assert(exn.getMessage.contains(code.name())) 13 | } 14 | } 15 | 16 | it should "contain the exception message" in { 17 | forAll { (message: String) => 18 | val exn = new ToxBootstrapException(ToxBootstrapException.Code.NULL, message) 19 | assert(exn.getMessage.contains(message)) 20 | } 21 | } 22 | 23 | "code" should "be the passed code" in { 24 | ToxBootstrapException.Code.values().foreach { code => 25 | val exn = new ToxBootstrapException(code) 26 | assert(exn.code == code) 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/FinalizerTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni 2 | 3 | import im.tox.tox4j.core.options.ToxOptions 4 | import org.scalatest.FlatSpec 5 | 6 | /** 7 | * These tests solely exist to exercise the C++ code paths that deal with closing and finalisation. If the C++ code has 8 | * errors in this area, these two tests can be used to single them out and debug them. 9 | * 10 | * Although [[System.gc()]] doesn't necessarily perform a GC, on the Oracle JVM it actually does reliably do so. 11 | * Thus, these tests don't formally test anything, but in reality they do. 12 | */ 13 | final class FinalizerTest extends FlatSpec { 14 | 15 | "Garbage collection" should "not crash the JVM when collecting a closed ToxCoreImpl" in { 16 | System.gc() 17 | new ToxCoreImpl[Unit](new ToxOptions).close() 18 | System.gc() 19 | } 20 | 21 | it should "not crash the JVM when collecting an unclosed ToxCoreImpl" in { 22 | System.gc() 23 | new ToxCoreImpl[Unit](new ToxOptions) 24 | System.gc() 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxBootstrapException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.JavaOnly; 4 | import im.tox.tox4j.exceptions.ToxException; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public final class ToxBootstrapException extends ToxException { 8 | 9 | public enum Code { 10 | /** 11 | * The public key was of invalid length. 12 | */ 13 | @JavaOnly BAD_KEY, 14 | /** 15 | * The address could not be resolved to an IP address, or the IP address 16 | * passed was invalid. 17 | */ 18 | BAD_HOST, 19 | /** 20 | * The port passed was invalid. The valid port range is (1, 65535). 21 | */ 22 | BAD_PORT, 23 | /** 24 | * An argument was null. 25 | */ 26 | NULL, 27 | } 28 | 29 | public ToxBootstrapException(@NotNull Code code) { 30 | this(code, ""); 31 | } 32 | 33 | public ToxBootstrapException(@NotNull Code code, String message) { 34 | super(code, message); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/SmallNat.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core 2 | 3 | import org.scalacheck.{Arbitrary, Gen} 4 | 5 | import scala.language.implicitConversions 6 | import scala.runtime.IntegralProxy 7 | 8 | /** 9 | * A wrapper class for [[Int]] to be used in property based testing where a 10 | * small positive integer is required (e.g. for array bounds). 11 | * 12 | * arbitrary[Int] generates numbers from the full range of integers, and is 13 | * thus unfit for allocation sizes and iteration counts. 14 | */ 15 | final case class SmallNat(self: Int) extends AnyVal with IntegralProxy[Int] { 16 | override protected def num = scala.math.Numeric.IntIsIntegral 17 | override protected def ord = scala.math.Ordering.Int 18 | override def isWhole(): Boolean = true 19 | } 20 | 21 | object SmallNat { 22 | final val MinValue = 0 23 | final val MaxValue = 100 24 | 25 | implicit val arbSmallNat: Arbitrary[SmallNat] = Arbitrary(Gen.choose(MinValue, MaxValue).map(apply)) 26 | implicit def smallNatToInt(smallNat: SmallNat): Int = smallNat.self 27 | } 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/util/exceptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "util/pp_attributes.h" 8 | 9 | 10 | void throw_tox_killed_exception (JNIEnv *env, jint instance_number, char const *message); 11 | void throw_illegal_state_exception (JNIEnv *env, jint instance_number, char const *message); 12 | void throw_illegal_state_exception (JNIEnv *env, jint instance_number, std::string const &message); 13 | void throw_tox_exception (JNIEnv *env, char const *module, char const *prefix, char const *method, char const *code); 14 | 15 | 16 | PP_NORETURN void tox4j_fatal_error (JNIEnv *env, char const *message); 17 | 18 | #define tox4j_fatal(message) tox4j_fatal_error (env, message) 19 | 20 | 21 | #define STR(token) STR_(token) 22 | #define STR_(token) #token 23 | #define tox4j_assert(condition) do { \ 24 | if (!(condition)) \ 25 | tox4j_fatal (__FILE__ ":" STR (__LINE__) ": Assertion failed: " #condition);\ 26 | } while (0) 27 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/crypto/exceptions/ToxKeyDerivationException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.crypto.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.JavaOnly; 4 | import im.tox.tox4j.exceptions.ToxException; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public final class ToxKeyDerivationException extends ToxException { 8 | 9 | public enum Code { 10 | /** 11 | * The salt was of incorrect length. 12 | */ 13 | @JavaOnly INVALID_LENGTH, 14 | /** 15 | * The crypto lib was unable to derive a key from the given passphrase, 16 | * which is usually a lack of memory issue. The functions accepting keys 17 | * do not produce this error. 18 | */ 19 | FAILED, 20 | /** 21 | * The passphrase was null or empty. 22 | */ 23 | NULL, 24 | } 25 | 26 | public ToxKeyDerivationException(@NotNull Code code) { 27 | this(code, ""); 28 | } 29 | 30 | public ToxKeyDerivationException(@NotNull Code code, String message) { 31 | super(code, message); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tools/ndk-install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -ex 4 | 5 | PREFIX=$1 6 | 7 | NDK_EXCLUDES="\ 8 | arch-mips 9 | */platforms/android-12 10 | */platforms/android-13 11 | */platforms/android-14 12 | */platforms/android-15 13 | */platforms/android-16 14 | */platforms/android-17 15 | */platforms/android-18 16 | */platforms/android-19 17 | */platforms/android-20 18 | */platforms/android-21 19 | */platforms/android-3 20 | */platforms/android-4 21 | */platforms/android-5 22 | */platforms/android-8 23 | */sources/cxx-stl/llvm-libc++* 24 | */tests 25 | */toolchains/*-4.9 26 | */toolchains/*-clang3.5 27 | */toolchains/aarch64* 28 | */toolchains/llvm-3.5 29 | */toolchains/mips*" 30 | 31 | NDK_VERSION=r10e 32 | NDK_PACKAGE=android-ndk-$NDK_VERSION-linux-x86_64.bin 33 | 34 | mkdir -p $PREFIX 35 | cd $PREFIX 36 | 37 | if [ ! -f $NDK_PACKAGE ]; then 38 | wget http://dl.google.com/android/ndk/$NDK_PACKAGE 39 | fi 40 | rm -rf android-ndk 41 | 7z x $NDK_PACKAGE `echo "$NDK_EXCLUDES" | sed 's/^/ -xr!/g'` | awk '/^Extracting/ { i++; if (i > 50) {print; i = 0}}' 42 | 43 | mv android-ndk-$NDK_VERSION android-ndk 44 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxAv/debug.cpp: -------------------------------------------------------------------------------- 1 | #include "ToxAv.h" 2 | 3 | #ifdef TOXAV_VERSION_MAJOR 4 | 5 | #include 6 | #include 7 | 8 | template<> 9 | void 10 | print_arg (protolog::Value &value, ToxAV *tox) 11 | { 12 | static std::vector ids; 13 | auto found = std::find (ids.begin (), ids.end (), tox); 14 | if (found == ids.end ()) 15 | { 16 | ids.push_back (tox); 17 | found = ids.end () - 1; 18 | } 19 | value.set_string ("@" + std::to_string (found - ids.begin () + 1)); 20 | } 21 | 22 | template<> 23 | void 24 | print_arg (protolog::Value &value, int16_t const *data) 25 | { 26 | if (data != nullptr) 27 | value.set_string ("out audio samples"); 28 | else 29 | value.set_string (""); 30 | } 31 | 32 | template<> 33 | void 34 | print_arg (protolog::Value &value, av::Events *events) 35 | { 36 | if (events != nullptr) 37 | value.set_string ("ByteSize ()) + "]>"); 38 | else 39 | value.set_string (""); 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/cpp/mock_jni.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | struct mock_jclass 9 | : _jclass 10 | { 11 | explicit mock_jclass (std::string name) 12 | : name (name) 13 | { } 14 | 15 | std::string name; 16 | }; 17 | 18 | 19 | struct mock_jthrowable 20 | : _jthrowable 21 | { 22 | mock_jthrowable (jclass clazz, std::string name) 23 | : clazz (static_cast (clazz)) 24 | , name (name) 25 | { } 26 | 27 | mock_jclass *clazz; 28 | std::string name; 29 | }; 30 | 31 | 32 | struct mock_jni 33 | : JNIEnv 34 | { 35 | mock_jni (JNINativeInterface_ const *functions) 36 | : JNIEnv { functions } 37 | { } 38 | 39 | 40 | jclass 41 | FindClass (const char *name) 42 | { 43 | return new mock_jclass (name); 44 | } 45 | 46 | jint 47 | ThrowNew (jclass clazz, const char *msg) 48 | { 49 | exn = new mock_jthrowable (clazz, msg); 50 | return 0; 51 | } 52 | 53 | 54 | mock_jthrowable *exn = nullptr; 55 | }; 56 | 57 | 58 | mock_jni *mock_jnienv (); 59 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCore/custom.cpp: -------------------------------------------------------------------------------- 1 | #include "ToxCore.h" 2 | 3 | #ifdef TOX_VERSION_MAJOR 4 | 5 | using namespace core; 6 | 7 | 8 | /* 9 | * Class: im_tox_tox4j_impl_ToxCoreJni 10 | * Method: toxFriendSendLossyPacket 11 | * Signature: (II[B)V 12 | */ 13 | TOX_METHOD (void, FriendSendLossyPacket, 14 | jint instanceNumber, jint friendNumber, jbyteArray packet) 15 | { 16 | ByteArray packetData (env, packet); 17 | return instances.with_instance_ign (env, instanceNumber, 18 | tox_friend_send_lossy_packet, friendNumber, packetData.data (), packetData.size () 19 | ); 20 | } 21 | 22 | /* 23 | * Class: im_tox_tox4j_impl_ToxCoreJni 24 | * Method: toxFriendSendLosslessPacket 25 | * Signature: (II[B)V 26 | */ 27 | TOX_METHOD (void, FriendSendLosslessPacket, 28 | jint instanceNumber, jint friendNumber, jbyteArray packet) 29 | { 30 | ByteArray packetData (env, packet); 31 | return instances.with_instance_ign (env, instanceNumber, 32 | tox_friend_send_lossless_packet, friendNumber, packetData.data (), packetData.size () 33 | ); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCrypto/generated/errors.cpp: -------------------------------------------------------------------------------- 1 | #include "../ToxCrypto.h" 2 | 3 | #ifdef TOX_DEFINED 4 | 5 | HANDLE ("Decryption", DECRYPTION) 6 | { 7 | switch (error) 8 | { 9 | success_case (DECRYPTION); 10 | failure_case (DECRYPTION, BAD_FORMAT); 11 | failure_case (DECRYPTION, FAILED); 12 | failure_case (DECRYPTION, INVALID_LENGTH); 13 | failure_case (DECRYPTION, KEY_DERIVATION_FAILED); 14 | failure_case (DECRYPTION, NULL); 15 | } 16 | return unhandled (); 17 | } 18 | 19 | HANDLE ("Encryption", ENCRYPTION) 20 | { 21 | switch (error) 22 | { 23 | success_case (ENCRYPTION); 24 | failure_case (ENCRYPTION, FAILED); 25 | failure_case (ENCRYPTION, KEY_DERIVATION_FAILED); 26 | failure_case (ENCRYPTION, NULL); 27 | } 28 | return unhandled (); 29 | } 30 | 31 | HANDLE ("KeyDerivation", KEY_DERIVATION) 32 | { 33 | switch (error) 34 | { 35 | success_case (KEY_DERIVATION); 36 | failure_case (KEY_DERIVATION, FAILED); 37 | failure_case (KEY_DERIVATION, NULL); 38 | } 39 | return unhandled (); 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCore/interaction.cpp: -------------------------------------------------------------------------------- 1 | #include "ToxCore.h" 2 | 3 | #ifdef TOX_VERSION_MAJOR 4 | 5 | using namespace core; 6 | 7 | 8 | /* 9 | * Class: im_tox_tox4j_impl_ToxCoreJni 10 | * Method: toxSelfSetTyping 11 | * Signature: (IIZ)V 12 | */ 13 | TOX_METHOD (void, SelfSetTyping, 14 | jint instanceNumber, jint friendNumber, jboolean isTyping) 15 | { 16 | return instances.with_instance_ign (env, instanceNumber, 17 | tox_self_set_typing, friendNumber, isTyping 18 | ); 19 | } 20 | 21 | 22 | /* 23 | * Class: im_tox_tox4j_impl_ToxCoreJni 24 | * Method: toxFriendSendMessage 25 | * Signature: (IIII[B)I 26 | */ 27 | TOX_METHOD (jint, FriendSendMessage, 28 | jint instanceNumber, jint friendNumber, jint messageType, jint timeDelta, jbyteArray message) 29 | { 30 | ByteArray const message_array (env, message); 31 | 32 | return instances.with_instance_err (env, instanceNumber, 33 | identity, 34 | tox_friend_send_message, friendNumber, enum_value (env, messageType), message_array.data (), message_array.size () 35 | ); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/SelfConnectionStatusCallbackTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxConnection 4 | import im.tox.tox4j.testing.autotest.AliceBobTest 5 | 6 | final class SelfConnectionStatusCallbackTest extends AliceBobTest { 7 | 8 | override protected def enableUdp = true 9 | override protected def enableTcp = true 10 | override protected def enableIpv4 = true 11 | override protected def enableIpv6 = true 12 | override protected def enableHttp = true 13 | override protected def enableSocks = true 14 | 15 | override type State = ToxConnection 16 | override def initialState: State = ToxConnection.NONE 17 | 18 | protected override def newChatClient(name: String, expectedFriendName: String) = new ChatClient(name, expectedFriendName) { 19 | 20 | override def selfConnectionStatus(connection: ToxConnection)(state: ChatState): ChatState = { 21 | super.selfConnectionStatus(connection)(state) 22 | assert(state.get != connection) 23 | state.set(connection).finish 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCore/ToxCore.h: -------------------------------------------------------------------------------- 1 | // Instance manager, JNI utilities. 2 | #include "tox4j/Tox4j.h" 3 | 4 | // Protobuf classes. 5 | #include "Core.pb.h" 6 | 7 | // JNI declarations from javah. 8 | #include "im_tox_tox4j_impl_jni_ToxCoreJni.h" 9 | 10 | // Header from toxcore. 11 | #include 12 | 13 | #ifndef SUBSYSTEM 14 | #define SUBSYSTEM TOX 15 | #define CLASS ToxCore 16 | #define PREFIX tox 17 | #endif 18 | 19 | #ifdef TOX_VERSION_MAJOR 20 | namespace core 21 | { 22 | namespace proto = im::tox::tox4j::core::proto; 23 | 24 | using Events = proto::CoreEvents; 25 | 26 | extern ToxInstances> instances; 27 | } 28 | #endif 29 | 30 | 31 | template 32 | typename java_array_t::array_type 33 | get_vector (Tox const *tox, JNIEnv *env) 34 | { 35 | std::vector name (get_size (tox)); 36 | get_data (tox, name.data ()); 37 | 38 | return toJavaArray (env, name); 39 | } 40 | 41 | 42 | template 43 | std::size_t 44 | constant_size (Tox const *) 45 | { 46 | return N; 47 | } 48 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/exceptions/ToxavNewException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.JavaOnly; 4 | import im.tox.tox4j.exceptions.ToxException; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public final class ToxavNewException extends ToxException { 8 | 9 | public enum Code { 10 | /** 11 | * The ToxCore implementation passed was not compatible with this ToxAv implementation. 12 | */ 13 | @JavaOnly INCOMPATIBLE, 14 | /** 15 | * Memory allocation failure while trying to allocate structures required for 16 | * the A/V session. 17 | */ 18 | MALLOC, 19 | /** 20 | * Attempted to create a second session for the same Tox instance. 21 | */ 22 | MULTIPLE, 23 | /** 24 | * One of the arguments to the function was NULL when it was not expected. 25 | */ 26 | NULL, 27 | } 28 | 29 | public ToxavNewException(@NotNull Code code) { 30 | this(code, ""); 31 | } 32 | 33 | public ToxavNewException(@NotNull Code code, String message) { 34 | super(code, message); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/bench/IterateTimingBench.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.bench 2 | 3 | import im.tox.tox4j.bench.PerformanceReportBase._ 4 | import im.tox.tox4j.bench.TimingReport 5 | import im.tox.tox4j.core.ToxCore 6 | import org.scalameter.KeyValue 7 | import org.scalameter.api._ 8 | 9 | final class IterateTimingBench extends TimingReport { 10 | 11 | protected override def confidence = Seq[KeyValue](exec.benchRuns -> 100) 12 | 13 | timing of classOf[ToxCore[Unit]] in { 14 | 15 | measure method "iterate" in { 16 | usingTox(iterations10k) in { 17 | case (sz, tox) => 18 | (0 until sz) foreach (_ => tox.iterate(())) 19 | } 20 | } 21 | 22 | measure method "iterationInterval" in { 23 | usingTox(iterations100k) in { 24 | case (sz, tox) => 25 | (0 until sz) foreach (_ => tox.iterationInterval) 26 | } 27 | } 28 | 29 | measure method "iterate+friends" in { 30 | using(iterations1k, toxWithFriends1k) in { 31 | case (sz, tox) => 32 | (0 until sz) foreach (_ => tox.iterate(())) 33 | } 34 | } 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/exceptions/ToxavCallControlException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxavCallControlException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The friend number did not designate a valid friend. 11 | */ 12 | FRIEND_NOT_FOUND, 13 | /** 14 | * This client is currently not in a call with the friend. Before the call is 15 | * answered, only CANCEL is a valid control 16 | */ 17 | FRIEND_NOT_IN_CALL, 18 | /** 19 | * Happens if user tried to pause an already paused call or if trying to 20 | * resume a call that is not paused. 21 | */ 22 | INVALID_TRANSITION, 23 | /** 24 | * Synchronization error occurred. 25 | */ 26 | SYNC, 27 | } 28 | 29 | public ToxavCallControlException(@NotNull Code code) { 30 | this(code, ""); 31 | } 32 | 33 | public ToxavCallControlException(@NotNull Code code, String message) { 34 | super(code, message); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/exceptions/ToxSetInfoExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions 2 | 3 | import im.tox.tox4j.ToxCoreTestBase 4 | import im.tox.tox4j.core.ToxCoreConstants 5 | import im.tox.tox4j.testing.ToxTestMixin 6 | import org.scalatest.FunSuite 7 | 8 | final class ToxSetInfoExceptionTest extends FunSuite with ToxTestMixin { 9 | 10 | test("SetNameTooLong") { 11 | val array = ToxCoreTestBase.randomBytes(ToxCoreConstants.MaxNameLength + 1) 12 | 13 | interceptWithTox(ToxSetInfoException.Code.TOO_LONG)( 14 | _.setName(array) 15 | ) 16 | } 17 | 18 | test("SetStatusMessageTooLong") { 19 | val array = ToxCoreTestBase.randomBytes(ToxCoreConstants.MaxStatusMessageLength + 1) 20 | 21 | interceptWithTox(ToxSetInfoException.Code.TOO_LONG)( 22 | _.setStatusMessage(array) 23 | ) 24 | } 25 | 26 | test("SetStatusMessageNull") { 27 | interceptWithTox(ToxSetInfoException.Code.NULL)( 28 | _.setStatusMessage(null) 29 | ) 30 | } 31 | 32 | test("SetNameNull") { 33 | interceptWithTox(ToxSetInfoException.Code.NULL)( 34 | _.setName(null) 35 | ) 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/exceptions/ToxavBitRateSetException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxavBitRateSetException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The friend_number passed did not designate a valid friend. 11 | */ 12 | FRIEND_NOT_FOUND, 13 | /** 14 | * This client is currently not in a call with the friend. 15 | */ 16 | FRIEND_NOT_IN_CALL, 17 | /** 18 | * The audio bit rate passed was not one of the supported values. 19 | */ 20 | INVALID_AUDIO_BIT_RATE, 21 | /** 22 | * The video bit rate passed was not one of the supported values. 23 | */ 24 | INVALID_VIDEO_BIT_RATE, 25 | /** 26 | * Synchronization error occurred. 27 | */ 28 | SYNC, 29 | } 30 | 31 | public ToxavBitRateSetException(@NotNull Code code) { 32 | this(code, ""); 33 | } 34 | 35 | public ToxavBitRateSetException(@NotNull Code code, String message) { 36 | super(code, message); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/enums/ToxavFriendCallState.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.enums; 2 | 3 | /** 4 | * Call state graph. 5 | */ 6 | public enum ToxavFriendCallState { 7 | /** 8 | * Set by the AV core if an error occurred on the remote end or if friend 9 | * timed out. This is the final state after which no more state 10 | * transitions can occur for the call. This call state will never be triggered 11 | * in combination with other call states. 12 | */ 13 | ERROR, 14 | 15 | /** 16 | * The call has finished. This is the final state after which no more state 17 | * transitions can occur for the call. This call state will never be 18 | * triggered in combination with other call states. 19 | */ 20 | FINISHED, 21 | 22 | /** 23 | * The flag that marks that friend is sending audio. 24 | */ 25 | SENDING_A, 26 | 27 | /** 28 | * The flag that marks that friend is sending video. 29 | */ 30 | SENDING_V, 31 | 32 | /** 33 | * The flag that marks that friend is receiving audio. 34 | */ 35 | ACCEPTING_A, 36 | 37 | /** 38 | * The flag that marks that friend is receiving video. 39 | */ 40 | ACCEPTING_V, 41 | } 42 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/impl/jni/AutoGenerated.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | 6 | /** 7 | * Mark methods that are to be generated by JniMethodImpls. 8 | * 9 | *

10 | * In {@link ToxCoreJni} and {@link ToxAvJni}, methods marked with this annotation do not need a manual implementation 11 | * in C++, as their JNI bridge implementations will be generated. This annotation exists only until the majority of 12 | * methods is generated, at which point there will be a "manual" override marker that inhibits auto-generation. 13 | * Ideally, all bridge method implementations will be generated, but in reality there are probably going to be some 14 | * complications that are too costly to overcome, so some manual overrides will remain. 15 | */ 16 | @Retention(RetentionPolicy.RUNTIME) 17 | public @interface AutoGenerated { 18 | /** 19 | * Override the C function name this native method should call. By default, a method called e.g. toxFooBar will call 20 | * the C function tox_foo_bar. This can be overridden here. 21 | */ 22 | String value() default ""; 23 | } 24 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/exceptions/ToxFriendSendMessageExceptionTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions 2 | 3 | import im.tox.tox4j.core.enums.ToxMessageType 4 | import im.tox.tox4j.testing.ToxTestMixin 5 | import org.scalatest.FunSuite 6 | 7 | final class ToxFriendSendMessageExceptionTest extends FunSuite with ToxTestMixin { 8 | 9 | test("SendMessageNotFound") { 10 | interceptWithTox(ToxFriendSendMessageException.Code.FRIEND_NOT_FOUND)( 11 | _.friendSendMessage(1, ToxMessageType.NORMAL, 0, "hello".getBytes) 12 | ) 13 | } 14 | 15 | test("SendMessageNotConnected") { 16 | interceptWithTox(ToxFriendSendMessageException.Code.FRIEND_NOT_CONNECTED)( 17 | _.friendSendMessage(0, ToxMessageType.NORMAL, 0, "hello".getBytes) 18 | ) 19 | } 20 | 21 | test("SendMessageNull") { 22 | interceptWithTox(ToxFriendSendMessageException.Code.NULL)( 23 | _.friendSendMessage(0, ToxMessageType.NORMAL, 0, null) 24 | ) 25 | } 26 | 27 | test("SendMessageEmpty") { 28 | interceptWithTox(ToxFriendSendMessageException.Code.EMPTY)( 29 | _.friendSendMessage(0, ToxMessageType.NORMAL, 0, "".getBytes) 30 | ) 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FriendMessageCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxMessageType 4 | import org.jetbrains.annotations.NotNull 5 | 6 | /** 7 | * This event is triggered when a message from a friend is received. 8 | */ 9 | trait FriendMessageCallback[ToxCoreState] { 10 | /** 11 | * @param friendNumber The friend number of the friend who sent the message. 12 | * @param messageType Message type (normal, action, ...). 13 | * @param timeDelta A delta in seconds between when the message was composed 14 | * and when it is being transmitted. For messages that are sent immediately, 15 | * it will be 0. If a message was written and couldn't be sent immediately 16 | * (due to a connection failure, for example), the timeDelta is an 17 | * approximation of when it was composed. 18 | * @param message The message data they sent. 19 | */ 20 | def friendMessage( 21 | friendNumber: Int, @NotNull messageType: ToxMessageType, timeDelta: Int, @NotNull message: Array[Byte] 22 | )(state: ToxCoreState): ToxCoreState = state 23 | } 24 | -------------------------------------------------------------------------------- /projects/linters/src/test/scala/im/tox/tox4j/lint/OptionOrNullTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.lint 2 | 3 | import org.brianmckenna.wartremover.test.WartTestTraverser 4 | import org.scalatest.FunSuite 5 | 6 | final class OptionOrNullTest extends FunSuite { 7 | 8 | test("Option#orNull cannot be used") { 9 | val result = WartTestTraverser(OptionOrNull) { 10 | def x = sys.env.get("some env").orNull 11 | } 12 | 13 | assert(result.errors == List(OptionOrNull.errorMessage)) 14 | } 15 | 16 | test("OptionOrNull respects @SuppressWarnings") { 17 | val result = WartTestTraverser(OptionOrNull) { 18 | @SuppressWarnings(Array("im.tox.tox4j.lint.OptionOrNull")) 19 | def x = sys.env.get("another env").orNull 20 | } 21 | 22 | assert(result.errors == Nil) 23 | } 24 | 25 | // A method called "orNull" should probably be flagged, anyway, 26 | // but this checker only looks for Option#orNull. 27 | test("other orNull methods are not flagged") { 28 | val result = WartTestTraverser(OptionOrNull) { 29 | class X { def orNull: String = "not really null" } 30 | def x = new X().orNull 31 | } 32 | 33 | assert(result.errors == Nil) 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCrypto/generated/natives.h: -------------------------------------------------------------------------------- 1 | // im.tox.tox4j.impl.jni.ToxCryptoJni 2 | JAVA_METHOD_REF (cryptoBox) 3 | CXX_FUNCTION_REF (crypto_box) 4 | JAVA_METHOD_REF (cryptoBoxAfternm) 5 | CXX_FUNCTION_REF (crypto_box_afternm) 6 | JAVA_METHOD_REF (cryptoBoxBeforenm) 7 | CXX_FUNCTION_REF (crypto_box_beforenm) 8 | JAVA_METHOD_REF (cryptoBoxKeypair) 9 | CXX_FUNCTION_REF (crypto_box_keypair) 10 | JAVA_METHOD_REF (cryptoBoxOpen) 11 | CXX_FUNCTION_REF (crypto_box_open) 12 | JAVA_METHOD_REF (cryptoBoxOpenAfternm) 13 | CXX_FUNCTION_REF (crypto_box_open_afternm) 14 | JAVA_METHOD_REF (randombytes) 15 | CXX_FUNCTION_REF (randombytes) 16 | JAVA_METHOD_REF (toxDeriveKeyFromPass) 17 | CXX_FUNCTION_REF (tox_derive_key_from_pass) 18 | JAVA_METHOD_REF (toxDeriveKeyWithSalt) 19 | CXX_FUNCTION_REF (tox_derive_key_with_salt) 20 | JAVA_METHOD_REF (toxGetSalt) 21 | CXX_FUNCTION_REF (tox_get_salt) 22 | JAVA_METHOD_REF (toxHash) 23 | CXX_FUNCTION_REF (tox_hash) 24 | JAVA_METHOD_REF (toxIsDataEncrypted) 25 | CXX_FUNCTION_REF (tox_is_data_encrypted) 26 | JAVA_METHOD_REF (toxPassKeyDecrypt) 27 | CXX_FUNCTION_REF (tox_pass_key_decrypt) 28 | JAVA_METHOD_REF (toxPassKeyEncrypt) 29 | CXX_FUNCTION_REF (tox_pass_key_encrypt) 30 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/org/scalastyle/scalariform/tox4j/ForBraceChecker.scala: -------------------------------------------------------------------------------- 1 | package org.scalastyle.scalariform.tox4j 2 | 3 | import org.scalastyle._ 4 | import org.scalastyle.scalariform.{AstChecker, VisitorHelper} 5 | 6 | import _root_.scalariform.lexer.{Token, Tokens} 7 | import _root_.scalariform.parser.{CompilationUnit, ForExpr} 8 | 9 | final class ForBraceChecker extends AstChecker("for.brace") { 10 | 11 | override def verify(ast: CompilationUnit, lines: Lines): List[ScalastyleError] = { 12 | for { 13 | t <- VisitorHelper.getAll[ForExpr](ast.immediateChildren.head) 14 | if t.lParenOrBrace.tokenType == Tokens.LBRACE && sameLine(t, lines) || 15 | t.lParenOrBrace.tokenType == Tokens.LPAREN && !sameLine(t, lines) 16 | } yield { 17 | PositionError(t.lParenOrBrace.offset) 18 | } 19 | } 20 | 21 | private def sameLine(t: ForExpr, lines: Lines): Boolean = { 22 | val startLine = getLine(t.lParenOrBrace, lines) 23 | val endLine = getLine(t.rParenOrBrace, lines) 24 | startLine == endLine 25 | } 26 | 27 | private def getLine(t: Token, lines: Lines): Int = { 28 | lines.toLineColumn(t.offset).map(_.line).getOrElse(0) 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/exceptions/ToxavAnswerException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxavAnswerException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * Failed to initialise codecs for call session. 11 | */ 12 | CODEC_INITIALIZATION, 13 | /** 14 | * The friend was valid, but they are not currently trying to initiate a call. 15 | * This is also returned if this client is already in a call with the friend. 16 | */ 17 | FRIEND_NOT_CALLING, 18 | /** 19 | * The friend number did not designate a valid friend. 20 | */ 21 | FRIEND_NOT_FOUND, 22 | /** 23 | * Audio or video bit rate is invalid. 24 | */ 25 | INVALID_BIT_RATE, 26 | /** 27 | * Synchronization error occurred. 28 | */ 29 | SYNC, 30 | } 31 | 32 | public ToxavAnswerException(@NotNull Code code) { 33 | this(code, ""); 34 | } 35 | 36 | public ToxavAnswerException(@NotNull Code code, String message) { 37 | super(code, message); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/exceptions/ToxavCallException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxavCallException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * Attempted to call a friend while already in an audio or video call with them. 11 | */ 12 | FRIEND_ALREADY_IN_CALL, 13 | /** 14 | * The friend was valid, but not currently connected. 15 | */ 16 | FRIEND_NOT_CONNECTED, 17 | /** 18 | * The friend number did not designate a valid friend. 19 | */ 20 | FRIEND_NOT_FOUND, 21 | /** 22 | * Audio or video bit rate is invalid. 23 | */ 24 | INVALID_BIT_RATE, 25 | /** 26 | * A memory allocation error occurred. 27 | */ 28 | MALLOC, 29 | /** 30 | * Synchronization error occurred. 31 | */ 32 | SYNC, 33 | } 34 | 35 | public ToxavCallException(@NotNull Code code) { 36 | this(code, ""); 37 | } 38 | 39 | public ToxavCallException(@NotNull Code code, String message) { 40 | super(code, message); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/networkPacket.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | let unpack_and_wrap ~dht ~buf kind = 4 | let unpacker : (module Packet.S) = 5 | let open Packet.Kind in 6 | match kind with 7 | | EchoRequest -> (module EchoRequest ) 8 | | EchoResponse -> (module EchoResponse ) 9 | | NodesRequest -> (module NodesRequest ) 10 | | NodesResponse -> (module NodesResponse) 11 | in 12 | 13 | let open Or_error in 14 | let module PacketModule = (val unpacker) in 15 | PacketModule.unpack ~dht ~buf >>| fun (node, decoded) -> 16 | node, PacketModule.wrap decoded 17 | 18 | 19 | let unpack ~dht ~buf = 20 | let open Or_error in 21 | Packet.Kind.unpack ~buf >>= (unpack_and_wrap ~dht ~buf) 22 | 23 | 24 | let pack ~dht ~node ~packet = 25 | let packer = 26 | let open Packet.Data in 27 | match packet with 28 | | EchoRequest packet -> EchoRequest.pack ~packet 29 | | EchoResponse packet -> EchoResponse.pack ~packet 30 | | NodesRequest packet -> NodesRequest.pack ~packet 31 | | NodesResponse packet -> NodesResponse.pack ~packet 32 | in 33 | 34 | let buf = Message.cipher () in 35 | packer ~dht ~buf ~node; 36 | Message.flip_lo buf; 37 | 38 | buf 39 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSendException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFileSendException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * This client is currently not connected to the friend. 11 | */ 12 | FRIEND_NOT_CONNECTED, 13 | /** 14 | * The friendNumber passed did not designate a valid friend. 15 | */ 16 | FRIEND_NOT_FOUND, 17 | /** 18 | * Filename length exceeded {@link ToxCoreConstants#MAX_FILENAME_LENGTH} bytes. 19 | */ 20 | NAME_TOO_LONG, 21 | /** 22 | * An argument was null. 23 | */ 24 | NULL, 25 | /** 26 | * Too many ongoing transfers. The maximum number of concurrent file transfers 27 | * is 256 per friend per direction (sending and receiving, so 512 total). 28 | */ 29 | TOO_MANY, 30 | } 31 | 32 | public ToxFileSendException(@NotNull Code code) { 33 | this(code, ""); 34 | } 35 | 36 | public ToxFileSendException(@NotNull Code code, String message) { 37 | super(code, message); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/dht.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | open Types 3 | 4 | 5 | type t = Types.dht 6 | 7 | 8 | let create () = 9 | let dht_sk, dht_pk = Crypto.random_keypair () in 10 | let dht_nodes = PublicKeyMap.empty in 11 | { dht_sk; dht_pk; dht_nodes; } 12 | 13 | 14 | let add_dht_node ~dht dht_node = 15 | { dht with 16 | dht_nodes = 17 | PublicKeyMap.add dht.dht_nodes 18 | ~key:dht_node.cn_node.n_key 19 | ~data:dht_node 20 | } 21 | 22 | 23 | let add_node ~dht node = 24 | match PublicKeyMap.find dht.dht_nodes node.n_key with 25 | | None -> 26 | add_dht_node ~dht { 27 | cn_node = node; 28 | cn_ckey = Crypto.precompute dht.dht_sk node.n_key; 29 | } 30 | | Some dht_node -> 31 | assert (PublicKey.equal node.n_key dht_node.cn_node.n_key); 32 | if dht_node.cn_node = node then 33 | dht 34 | else 35 | add_dht_node ~dht { 36 | dht_node with 37 | cn_node = node; 38 | } 39 | 40 | 41 | exception No_such_key 42 | 43 | let node_by_key ~dht public_key = 44 | match PublicKeyMap.find dht.dht_nodes public_key with 45 | | None -> 46 | Or_error.of_exn No_such_key 47 | | Some node -> 48 | Or_error.return node 49 | -------------------------------------------------------------------------------- /projects/build-basic/depends.sbt: -------------------------------------------------------------------------------- 1 | /** 2 | * The build configuration in this project is split up into dependencies and 3 | * build configuration. We do this so that it can be shared between the SBT 4 | * build and the project build itself. This way, this project can benefit from 5 | * the checkers and formatters provided by itself, recursively. 6 | */ 7 | 8 | resolvers += Classpaths.sbtPluginReleases 9 | resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/" 10 | 11 | // Code style. 12 | addSbtPlugin("com.etsy" % "sbt-checkstyle-plugin" % "0.5.1") 13 | addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "0.8.0") 14 | addSbtPlugin("de.johoop" % "findbugs4sbt" % "1.4.0") 15 | 16 | // Code formatting. 17 | addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0") 18 | 19 | // Scala protobuf support. 20 | addSbtPlugin("com.trueaccord.scalapb" % "sbt-scalapb" % "0.5.9") 21 | 22 | // Build dependencies. 23 | libraryDependencies ++= Seq( 24 | "commons-io" % "commons-io" % "2.4", 25 | "org.ow2.asm" % "asm-all" % "5.0.2", 26 | "javassist" % "javassist" % "3.12.1.GA" 27 | ) 28 | 29 | // Test dependencies. 30 | libraryDependencies ++= Seq( 31 | "org.scalatest" %% "scalatest" % "2.2.4" 32 | ) map (_ % Test) 33 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFileSeekException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFileSeekException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * File was not in a state where it could be seeked. 11 | */ 12 | DENIED, 13 | /** 14 | * This client is currently not connected to the friend. 15 | */ 16 | FRIEND_NOT_CONNECTED, 17 | /** 18 | * The friendNumber passed did not designate a valid friend. 19 | */ 20 | FRIEND_NOT_FOUND, 21 | /** 22 | * Seek position was invalid. 23 | */ 24 | INVALID_POSITION, 25 | /** 26 | * No file transfer with the given file number was found for the given friend. 27 | */ 28 | NOT_FOUND, 29 | /** 30 | * An allocation error occurred while increasing the send queue size. 31 | */ 32 | SENDQ, 33 | } 34 | 35 | public ToxFileSeekException(@NotNull Code code) { 36 | this(code, ""); 37 | } 38 | 39 | public ToxFileSeekException(@NotNull Code code, String message) { 40 | super(code, message); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendSendMessageException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFriendSendMessageException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * Attempted to send a zero-length message. 11 | */ 12 | EMPTY, 13 | /** 14 | * This client is currently not connected to the friend. 15 | */ 16 | FRIEND_NOT_CONNECTED, 17 | /** 18 | * The friend number did not designate a valid friend. 19 | */ 20 | FRIEND_NOT_FOUND, 21 | /** 22 | * An argument was null. 23 | */ 24 | NULL, 25 | /** 26 | * An allocation error occurred while increasing the send queue size. 27 | */ 28 | SENDQ, 29 | /** 30 | * Message length exceeded {@link ToxCoreConstants#MAX_MESSAGE_LENGTH}. 31 | */ 32 | TOO_LONG, 33 | } 34 | 35 | public ToxFriendSendMessageException(@NotNull Code code) { 36 | this(code, ""); 37 | } 38 | 39 | public ToxFriendSendMessageException(@NotNull Code code, String message) { 40 | super(code, message); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/core/random/RandomCore.scala: -------------------------------------------------------------------------------- 1 | package im.tox.core.random 2 | 3 | import java.nio.ByteBuffer 4 | 5 | import im.tox.tox4j.impl.jni.ToxCryptoJni 6 | import org.jetbrains.annotations.NotNull 7 | 8 | object RandomCore { 9 | 10 | def randomBytes(length: Int): Array[Byte] = { 11 | val bytes = Array.ofDim[Byte](length) 12 | ToxCryptoJni.randombytes(bytes) 13 | bytes 14 | } 15 | 16 | def randomByteBuffer(length: Int): ByteBuffer = { 17 | val bytes = randomBytes(length) 18 | ByteBuffer.wrap(bytes) 19 | } 20 | 21 | def randomLong(): Long = { 22 | randomByteBuffer(java.lang.Long.SIZE / java.lang.Byte.SIZE).getLong 23 | } 24 | 25 | def entropy(@NotNull data: Seq[Byte]): Double = { 26 | val frequencies = new Array[Int](-Byte.MinValue * 2) 27 | for (b <- data) { 28 | frequencies(Byte.MaxValue - b) += 1 29 | } 30 | 31 | val probabilities = 32 | for (frequency <- frequencies) yield { 33 | if (frequency != 0) { 34 | val probability = frequency.toDouble / data.length 35 | -probability * (Math.log(probability) / Math.log(-Byte.MinValue * 2)) 36 | } else { 37 | 0 38 | } 39 | } 40 | probabilities.sum 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/internal/EventTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni.internal 2 | 3 | import org.scalatest.FlatSpec 4 | 5 | class EventTest extends FlatSpec { 6 | 7 | "callback" should "be called on run()" in { 8 | val event = new Event 9 | var called = false 10 | 11 | val id = event += (() => called = true) 12 | 13 | event() 14 | assert(called) 15 | } 16 | 17 | it should "be called twice if run() is called twice" in { 18 | val event = new Event 19 | var called = 0 20 | 21 | val id = event += (() => called += 1) 22 | 23 | event() 24 | assert(called == 1) 25 | event() 26 | assert(called == 2) 27 | } 28 | 29 | it should "not be called if it was deleted" in { 30 | val event = new Event 31 | var called = false 32 | 33 | val id = event += (() => called = true) 34 | 35 | event -= id 36 | 37 | event() 38 | assert(!called) 39 | } 40 | 41 | "remove" should "be idempotent" in { 42 | val event = new Event 43 | var called = 0 44 | 45 | val id1 = event += (() => called = 1) 46 | val id2 = event += (() => called = 2) 47 | 48 | event -= id1 49 | event -= id1 50 | 51 | event() 52 | assert(called == 2) 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /projects/build-basic/src/test/scala/org/scalastyle/scalariform/tox4j/RedundantValCheckerTest.scala: -------------------------------------------------------------------------------- 1 | package org.scalastyle.scalariform.tox4j 2 | 3 | import org.scalastyle.scalariform.CheckerTest 4 | 5 | final class RedundantValCheckerTest extends CheckerTest(new RedundantValChecker) { 6 | 7 | test("flag redundant val in case classes") { 8 | assertErrors(1, "case class Foo(!!val thing: Int)") 9 | } 10 | 11 | test("flag redundant val in final case classes") { 12 | assertErrors(1, "final case class Foo(!!val thing: Int)") 13 | } 14 | 15 | test("do not flag var in case classes") { 16 | assertErrors(0, "case class Foo(var thing: Int)") 17 | } 18 | 19 | test("do not flag case classes without val") { 20 | assertErrors(0, "case class Foo(thing: Int)") 21 | assertErrors(0, "final case class Foo(thing: Int)") 22 | assertErrors(0, "abstract case class Foo(thing: Int)") 23 | } 24 | 25 | test("do not flag normal classes with val inside case classes") { 26 | assertErrors(0, """ 27 | case class Foo(thing: Int) { 28 | class Bar(val otherThing: Int) 29 | }""") 30 | } 31 | 32 | test("do not flag val in non-case classes") { 33 | assertErrors(0, """ 34 | class Foo(val thing: Int) 35 | abstract class Foo(val thing: Int) 36 | final class Foo(val thing: Int)""") 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/NameEmptyTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.testing.autotest.{AliceBobTest, AliceBobTestBase} 4 | 5 | final class NameEmptyTest extends AliceBobTest { 6 | 7 | override type State = Int 8 | override def initialState: State = 0 9 | 10 | protected override def newChatClient(name: String, expectedFriendName: String) = new ChatClient(name, expectedFriendName) { 11 | 12 | override def friendName(friendNumber: Int, name: Array[Byte])(state: ChatState): ChatState = { 13 | debug("friend changed name to: " + new String(name)) 14 | assert(friendNumber == AliceBobTestBase.FriendNumber) 15 | 16 | state.get match { 17 | case 0 => 18 | // Initial empty name 19 | assert(name.isEmpty) 20 | 21 | state.addTask { (tox, state) => 22 | tox.setName("One".getBytes) 23 | state 24 | }.set(1) 25 | 26 | case 1 => 27 | assert(new String(name) == "One") 28 | 29 | state.addTask { (tox, state) => 30 | tox.setName("".getBytes) 31 | state 32 | }.set(2) 33 | 34 | case 2 => 35 | assert(name.isEmpty) 36 | state.finish 37 | } 38 | } 39 | 40 | } 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/crypto.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | open Sodium 3 | 4 | 5 | let precompute = Box.precompute 6 | let random_keypair = Box.random_keypair 7 | 8 | 9 | let fast_box_open ~channel_key ~nonce cipher_text = 10 | Or_error.try_with 11 | (fun () -> Box.Bytes.fast_box_open channel_key cipher_text nonce) 12 | 13 | let decrypt ~channel_key ~nonce cipher_text = 14 | let open Or_error in 15 | cipher_text 16 | |> Message.Consume.string 17 | |> Bytes.unsafe_of_string 18 | |> fast_box_open ~channel_key ~nonce 19 | >>| fun plain_text -> 20 | plain_text 21 | |> Bytes.unsafe_to_string 22 | 23 | let unpack_encrypted ~channel_key ~nonce cipher_text = 24 | let open Or_error in 25 | decrypt ~channel_key ~nonce cipher_text 26 | >>| Message.plain_of_string 27 | 28 | 29 | let fast_box ~channel_key ~nonce plain_text = 30 | Box.Bytes.fast_box channel_key plain_text nonce 31 | 32 | let encrypt ~channel_key ~nonce plain_text = 33 | plain_text 34 | |> Message.to_string 35 | |> Bytes.unsafe_of_string 36 | |> fast_box ~channel_key ~nonce 37 | |> Bytes.unsafe_to_string 38 | 39 | let pack_encrypted ~channel_key ~nonce ~buf ~f = 40 | let plain = Message.plain () in 41 | f ~buf:plain; 42 | Message.flip_lo plain; 43 | 44 | encrypt ~channel_key ~nonce plain 45 | |> Message.Fill.string buf 46 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/domain/FileTransferIncoming.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.domain 2 | 3 | import java.io.{File, FileNotFoundException, IOException, RandomAccessFile} 4 | 5 | import org.slf4j.LoggerFactory 6 | 7 | final class FileTransferIncoming(file: File, kind: Int, size: Long) extends FileTransfer(file) { 8 | private val logger = LoggerFactory.getLogger(classOf[FileTransferIncoming]) 9 | 10 | private var input: RandomAccessFile = null 11 | 12 | @throws[FileNotFoundException] 13 | def resume(): Unit = { 14 | if (this.input != null) { 15 | logger.warn("RESUME received with open file; not re-opening") 16 | } else { 17 | this.input = new RandomAccessFile(file, "rw") 18 | } 19 | } 20 | 21 | @throws[IOException] 22 | def read(position: Long, length: Int): Array[Byte] = { 23 | throw new IOException("Cannot read from incoming file") 24 | } 25 | 26 | @throws[IOException] 27 | def close(): Unit = { 28 | input.close() 29 | } 30 | 31 | @throws[IOException] 32 | def write(position: Long, data: Array[Byte]): Unit = { 33 | if (input == null) { 34 | logger.warn("Writing before receiving a RESUME control; opening file anyway") 35 | input = new RandomAccessFile(file, "w") 36 | } 37 | input.seek(position) 38 | input.write(data) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/events/AddFriendButtonOnAction.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.events 2 | 3 | import java.awt.event.{ActionEvent, ActionListener} 4 | import javax.swing._ 5 | 6 | import im.tox.gui.MainView 7 | import im.tox.tox4j.ToxCoreTestBase.parsePublicKey 8 | import im.tox.tox4j.core.ToxCoreConstants 9 | import im.tox.tox4j.core.exceptions.ToxFriendAddException 10 | 11 | final class AddFriendButtonOnAction(toxGui: MainView) extends ActionListener { 12 | 13 | override def actionPerformed(event: ActionEvent): Unit = { 14 | try { 15 | val publicKey = parsePublicKey(toxGui.friendId.getText) 16 | 17 | val friendNumber = 18 | if (toxGui.friendRequest.getText.isEmpty) { 19 | toxGui.tox.addFriendNorequest(publicKey) 20 | } else { 21 | toxGui.tox.addFriend(publicKey, toxGui.friendRequest.getText.getBytes) 22 | } 23 | 24 | toxGui.friendListModel.add(friendNumber, publicKey.slice(0, ToxCoreConstants.PublicKeySize)) 25 | toxGui.addMessage("Added friend number ", friendNumber) 26 | toxGui.save() 27 | } catch { 28 | case e: ToxFriendAddException => 29 | toxGui.addMessage("Add friend failed: ", e.code) 30 | case e: Throwable => 31 | JOptionPane.showMessageDialog(toxGui, MainView.printExn(e)) 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/ToxImplBase.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import com.typesafe.scalalogging.Logger 4 | import org.slf4j.LoggerFactory 5 | 6 | import scala.util.control.NonFatal 7 | 8 | object ToxImplBase { 9 | 10 | private val logger = Logger(LoggerFactory.getLogger(this.getClass)) 11 | 12 | /** 13 | * Calls a callback and catches any [[NonFatal]] exceptions it throws and logs them. 14 | * 15 | * @param fatal If this is false, exceptions thrown by callbacks are caught and logged. 16 | * @param state State to pass through the callback. 17 | * @param eventHandler The callback object. 18 | * @param callback The method to call on the callback object. 19 | * @tparam T The type of the callback object. 20 | */ 21 | @SuppressWarnings(Array("org.brianmckenna.wartremover.warts.Throw")) 22 | @inline 23 | def tryAndLog[ToxCoreState, T](fatal: Boolean, state: ToxCoreState, eventHandler: T)(callback: T => ToxCoreState => ToxCoreState): ToxCoreState = { 24 | if (!fatal) { 25 | try { 26 | callback(eventHandler)(state) 27 | } catch { 28 | case NonFatal(e) => 29 | logger.warn("Exception caught while executing " + eventHandler.getClass.getName, e) 30 | state 31 | } 32 | } else { 33 | callback(eventHandler)(state) 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/JavaLibraryPath.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j 2 | 3 | import java.io.File 4 | 5 | object JavaLibraryPath { 6 | /** 7 | * Appends a path to the java.library.path property and to [[ClassLoader]]'s private static 8 | * [[ClassLoader.usr_paths]] String array field. 9 | * 10 | * @param path Path to add to the property and ClassLoader search path. 11 | * @throws IllegalAccessException If the security context did not allow writing to private fields. 12 | */ 13 | @throws[IllegalAccessException] 14 | def addLibraryPath(path: String): Unit = { 15 | val field = 16 | try { 17 | classOf[ClassLoader].getDeclaredField("usr_paths") 18 | } catch { 19 | case e: NoSuchFieldException => 20 | throw new RuntimeException("Implementation of ClassLoader changed: usr_paths field no longer exists", e) 21 | } 22 | field.setAccessible(true) 23 | 24 | val paths = field.get(null).asInstanceOf[Array[String]] 25 | if (!paths.contains(path)) { 26 | val tmp = new Array[String](paths.length + 1) 27 | System.arraycopy(paths, 0, tmp, 0, paths.length) 28 | tmp(paths.length) = path 29 | field.set(null, tmp) 30 | 31 | System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + path) 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/options/ToxOptionsTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.options 2 | 3 | import org.scalatest.FlatSpec 4 | 5 | final class ToxOptionsTest extends FlatSpec { 6 | 7 | "tox options" should "not allow negative ports" in { 8 | intercept[IllegalArgumentException] { 9 | ToxOptions(startPort = -1) 10 | } 11 | intercept[IllegalArgumentException] { 12 | ToxOptions(endPort = -1) 13 | } 14 | intercept[IllegalArgumentException] { 15 | ToxOptions(tcpPort = -1) 16 | } 17 | } 18 | 19 | it should "allow the port to be 0" in { 20 | ToxOptions(startPort = 0, endPort = 0, tcpPort = 0) 21 | } 22 | 23 | it should "allow the port to be 65535" in { 24 | ToxOptions(startPort = 65535, endPort = 65535, tcpPort = 65535) 25 | } 26 | 27 | it should "not allow the port to be greater than 65535" in { 28 | intercept[IllegalArgumentException] { 29 | ToxOptions(startPort = 65536) 30 | } 31 | intercept[IllegalArgumentException] { 32 | ToxOptions(endPort = 65536) 33 | } 34 | intercept[IllegalArgumentException] { 35 | ToxOptions(tcpPort = 65536) 36 | } 37 | } 38 | 39 | it should "require startPort <= endPort" in { 40 | intercept[IllegalArgumentException] { 41 | ToxOptions(startPort = 2, endPort = 1) 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/bench/ToxCoreTimingBench.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.bench 2 | 3 | import im.tox.tox4j.bench.PerformanceReportBase._ 4 | import im.tox.tox4j.bench.TimingReport 5 | import im.tox.tox4j.core.callbacks.ToxEventAdapter 6 | import im.tox.tox4j.core.{ToxCore, ToxCoreConstants} 7 | import org.scalameter.api._ 8 | 9 | final class ToxCoreTimingBench extends TimingReport { 10 | 11 | timing of classOf[ToxCore[Unit]] in { 12 | 13 | measure method "bootstrap" in { 14 | val publicKey = Array.ofDim[Byte](ToxCoreConstants.PublicKeySize) 15 | usingTox(nodes) in { 16 | case (sz, tox) => 17 | (0 until sz) foreach (_ => tox.bootstrap("localhost", 8080, publicKey)) 18 | } 19 | } 20 | 21 | measure method "addTcpRelay" in { 22 | val publicKey = Array.ofDim[Byte](ToxCoreConstants.PublicKeySize) 23 | usingTox(nodes) in { 24 | case (sz, tox) => 25 | (0 until sz) foreach (_ => tox.addTcpRelay("localhost", 8080, publicKey)) 26 | } 27 | } 28 | 29 | measure method "callback" in { 30 | val ignoreEvents = new ToxEventAdapter[Unit] 31 | usingTox(iterations1000k) config (exec.benchRuns -> 100) in { 32 | case (sz, tox) => 33 | (0 until sz) foreach (_ => tox.callback(ignoreEvents)) 34 | } 35 | } 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/FilePauseResumeWithControlTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.ToxCore 4 | import im.tox.tox4j.core.enums.ToxFileControl 5 | 6 | final class FilePauseResumeWithControlTest extends FilePauseResumeTestBase { 7 | 8 | protected override def newChatClient(name: String, expectedFriendName: String) = new Alice(name, expectedFriendName) 9 | 10 | final class Alice(name: String, expectedFriendName: String) extends super.Alice(name, expectedFriendName) { 11 | 12 | protected override def addFriendMessageTask(friendNumber: Int, bobSentFileNumber: Int, fileId: Array[Byte], tox: ToxCore[ChatState]): Unit = { 13 | debug("send resume control") 14 | if (isBob) { 15 | tox.fileControl(friendNumber, bobSentFileNumber, ToxFileControl.RESUME) 16 | bobShouldPause = 1 17 | } else if (isAlice) { 18 | tox.fileControl(friendNumber, aliceSentFileNumber, ToxFileControl.RESUME) 19 | aliceShouldPause = 1 20 | } 21 | } 22 | 23 | protected override def addFileRecvTask(friendNumber: Int, fileNumber: Int, bobSentFileNumber: Int, bobOffset: Long, tox: ToxCore[ChatState]): Unit = { 24 | debug(s"sending control RESUME for $fileNumber") 25 | tox.fileControl(friendNumber, fileNumber, ToxFileControl.RESUME) 26 | } 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FileRecvChunkCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import org.jetbrains.annotations.NotNull 4 | 5 | /** 6 | * This event is first triggered when a file transfer request is received, and 7 | * subsequently when a chunk of file data for an accepted request was received. 8 | */ 9 | trait FileRecvChunkCallback[ToxCoreState] { 10 | /** 11 | * When length is 0, the transfer is finished and the client should release the 12 | * resources it acquired for the transfer. After a call with length = 0, the 13 | * file number can be reused for new file transfers. 14 | * 15 | * If position is equal to file_size (received in the [[FileRecvCallback]] callback) 16 | * when the transfer finishes, the file was received completely. Otherwise, if 17 | * fileSize was negative, streaming ended successfully when length is 0. 18 | * 19 | * @param friendNumber The friend number of the friend who is sending the file. 20 | * @param fileNumber The friend-specific file number the data received is associated with. 21 | * @param position The file position of the first byte in data. 22 | * @param data A byte array containing the received chunk. 23 | */ 24 | def fileRecvChunk( 25 | friendNumber: Int, fileNumber: Int, position: Long, @NotNull data: Array[Byte] 26 | )(state: ToxCoreState): ToxCoreState = state 27 | } 28 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/callbacks/FileRecvCallback.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxFileControl 4 | import org.jetbrains.annotations.NotNull 5 | 6 | /** 7 | * This event is triggered when a file transfer request is received. 8 | */ 9 | trait FileRecvCallback[ToxCoreState] { 10 | /** 11 | * The client should acquire resources to be associated with the file transfer. 12 | * Incoming file transfers start in the PAUSED state. After this callback 13 | * returns, a transfer can be rejected by sending a [[ToxFileControl.CANCEL]] 14 | * control command before any other control commands. It can be accepted by 15 | * sending [[ToxFileControl.RESUME]]. 16 | * 17 | * @param friendNumber The friend number of the friend who is sending the file transfer request. 18 | * @param fileNumber The friend-specific file number the data received is associated with. 19 | * @param kind The meaning of the file to be sent. 20 | * @param fileSize Size in bytes of the file the client wants to send, -1 if unknown or streaming. 21 | * @param filename Name of the file. May not be the actual name. This name was sent along with the file send request. 22 | */ 23 | def fileRecv( 24 | friendNumber: Int, fileNumber: Int, kind: Int, fileSize: Long, @NotNull filename: Array[Byte] 25 | )(state: ToxCoreState): ToxCoreState = state 26 | } 27 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/message.mli: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | 4 | type cipher 5 | type plain 6 | 7 | type ('encryption, 'access, 'seek) t 8 | 9 | 10 | val cipher : unit -> (cipher, 'b, 'c) t 11 | val plain : unit -> (plain , 'b, 'c) t 12 | 13 | val cipher_of_string : string -> (cipher, 'b, 'c) t 14 | val plain_of_string : string -> (plain , 'b, 'c) t 15 | 16 | val of_iobuf 17 | : ('access, Iobuf.seek) Iobuf.t 18 | -> (cipher, read_only, Iobuf.seek) t 19 | 20 | val to_iobuf 21 | : (cipher, 'access, Iobuf.seek) t 22 | -> (read_only, Iobuf.seek) Iobuf.t 23 | 24 | val flip_lo : ('a, 'b, Iobuf.seek) t -> unit 25 | val to_string : ?len:int -> ('a, 'b, 'c) t -> string 26 | 27 | 28 | module type Accessor = sig 29 | type ('encryption, 'a) t 30 | 31 | val uint8 : ('encryption, int ) t 32 | val uint16_be : ('encryption, int ) t 33 | val int64_t_be : ('encryption, int64 ) t 34 | val string : ?str_pos:int -> ?len:int 35 | -> ('encryption, string) t 36 | end 37 | 38 | module Consume : sig 39 | type 'encryption src = ('encryption, read_only, Iobuf.seek) t 40 | 41 | include Accessor with 42 | type ('encryption, 'a) t = 'encryption src -> 'a 43 | end 44 | 45 | 46 | module Fill : sig 47 | type 'encryption src = ('encryption, read_write, Iobuf.seek) t 48 | 49 | include Accessor with 50 | type ('encryption, 'a) t = 'encryption src -> 'a -> unit 51 | end 52 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/forms/MainViewBase.java: -------------------------------------------------------------------------------- 1 | package im.tox.gui.forms; 2 | 3 | import im.tox.gui.domain.Friend; 4 | 5 | import javax.swing.*; 6 | 7 | public class MainViewBase extends JFrame { 8 | 9 | public JList messages; 10 | public JTabbedPane tabbedPane1; 11 | public JButton connectButton; 12 | public JCheckBox enableIPv6CheckBox; 13 | public JCheckBox enableUdpCheckBox; 14 | public JRadioButton noneRadioButton; 15 | public JRadioButton httpRadioButton; 16 | public JRadioButton socksRadioButton; 17 | public JTextField proxyHost; 18 | public JTextField bootstrapHost; 19 | public JTextField bootstrapPort; 20 | public JTextField bootstrapKey; 21 | public JButton bootstrapButton; 22 | public JPanel contentPane; 23 | public JTextField proxyPort; 24 | public JTextField friendId; 25 | public JButton addFriendButton; 26 | public JTextField friendRequest; 27 | public JList friendList; 28 | public JTextField messageText; 29 | public JRadioButton messageRadioButton; 30 | public JRadioButton actionRadioButton; 31 | public JButton sendButton; 32 | public JTextField selfPublicKey; 33 | public JTextField fileName; 34 | public JProgressBar fileProgress; 35 | public JButton sendFileButton; 36 | 37 | public MainViewBase() { 38 | setContentPane(contentPane); 39 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/crypto/exceptions/ToxDecryptionException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.crypto.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxDecryptionException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The input data is missing the magic number (i.e. wasn't created by this 11 | * module, or is corrupted) 12 | */ 13 | BAD_FORMAT, 14 | /** 15 | * The encrypted byte array could not be decrypted. Either the data was 16 | * corrupt or the password/key was incorrect. 17 | */ 18 | FAILED, 19 | /** 20 | * The input data was shorter than {@link ToxCryptoConstants.ENCRYPTION_EXTRA_LENGTH} bytes. 21 | */ 22 | INVALID_LENGTH, 23 | /** 24 | * The crypto lib was unable to derive a key from the given passphrase, 25 | * which is usually a lack of memory issue. The functions accepting keys 26 | * do not produce this error. 27 | */ 28 | KEY_DERIVATION_FAILED, 29 | /** 30 | * The key or input data was null or empty. 31 | */ 32 | NULL, 33 | } 34 | 35 | public ToxDecryptionException(@NotNull Code code) { 36 | this(code, ""); 37 | } 38 | 39 | public ToxDecryptionException(@NotNull Code code, String message) { 40 | super(code, message); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/options/ProxyOptionsTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.options 2 | 3 | import im.tox.tox4j.core.enums.ToxProxyType 4 | import org.scalatest.FlatSpec 5 | 6 | final class ProxyOptionsTest extends FlatSpec { 7 | 8 | "proxy options" should "not allow negative ports" in { 9 | intercept[IllegalArgumentException] { 10 | ProxyOptions.Http("localhost", -1) 11 | } 12 | intercept[IllegalArgumentException] { 13 | ProxyOptions.Socks5("localhost", -1) 14 | } 15 | } 16 | 17 | it should "allow the port to be 0" in { 18 | ProxyOptions.Http("localhost", 0) 19 | ProxyOptions.Socks5("localhost", 0) 20 | } 21 | 22 | it should "allow the port to be 65535" in { 23 | ProxyOptions.Http("localhost", 65535) 24 | ProxyOptions.Socks5("localhost", 65535) 25 | } 26 | 27 | it should "not allow the port to be greater than 65535" in { 28 | intercept[IllegalArgumentException] { 29 | ProxyOptions.Http("localhost", 65536) 30 | } 31 | intercept[IllegalArgumentException] { 32 | ProxyOptions.Socks5("localhost", 65536) 33 | } 34 | } 35 | 36 | it should "produce the right low level enum values" in { 37 | assert(ProxyOptions.None.proxyType == ToxProxyType.NONE) 38 | assert(ProxyOptions.Http("localhost", 1).proxyType == ToxProxyType.HTTP) 39 | assert(ProxyOptions.Socks5("localhost", 1).proxyType == ToxProxyType.SOCKS5) 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tools/dependency-analyser: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use common::sense; 4 | use Data::Dumper; 5 | 6 | local $Data::Dumper::Sortkeys = 1; 7 | local $Data::Dumper::Terse = 1; 8 | local $Data::Dumper::Indent = 1; 9 | 10 | my $dep; 11 | 12 | for my $file (@ARGV) { 13 | open my $fh, '<', $file 14 | or die "Could not open '$file' for reading: $!"; 15 | 16 | my $class; 17 | for (<$fh>) { 18 | s/<(?>[^<>]|(?R))*>//g; 19 | 20 | if (/^Compiled from|^$|^ public static \{\};$|^ Code:$|^\}$/) { 21 | # Ignore 22 | } 23 | 24 | elsif (/^[a-z].*\b(?:class|interface)\b (.+) \{/) { 25 | my ($className, $extends, $implements) = $1 =~ /^(.+?)(?: extends (.+?))?(?: implements (.+?))?$/; 26 | my @super = ( 27 | split ",", $extends, 28 | split ",", $implements, 29 | ); 30 | $class = $dep->{$className} = { 31 | name => $className, 32 | super => \@super, 33 | }; 34 | } 35 | 36 | elsif (/^ public static final ([^ ]+) [^ ]+;$/) { 37 | say $1; 38 | } 39 | 40 | elsif (/^ private \Q$class->{name}\E\((.*)\);$/) { 41 | say $1; 42 | } 43 | 44 | elsif (/^ +\d+: \w+[^\/]+(?:\/\/ (.*))?$/) { 45 | if ($1) { 46 | say $1; 47 | } 48 | } 49 | 50 | else { 51 | die $_; 52 | } 53 | } 54 | 55 | last 56 | } 57 | 58 | print Dumper $dep; 59 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/ToxCore/generated/constants.h: -------------------------------------------------------------------------------- 1 | // im.tox.tox4j.core.ToxCoreConstants$ 2 | void 3 | checkToxCoreConstants () 4 | { 5 | static_assert (TOX_ADDRESS_SIZE == 38, "Java constant out of sync with C"); 6 | static_assert (TOX_DEFAULT_END_PORT == 33545, "Java constant out of sync with C"); 7 | static_assert (TOX_DEFAULT_PROXY_PORT == 8080, "Java constant out of sync with C"); 8 | static_assert (TOX_DEFAULT_START_PORT == 33445, "Java constant out of sync with C"); 9 | static_assert (TOX_DEFAULT_TCP_PORT == 0, "Java constant out of sync with C"); 10 | static_assert (TOX_FILE_ID_LENGTH == 32, "Java constant out of sync with C"); 11 | static_assert (TOX_MAX_CUSTOM_PACKET_SIZE == 1373, "Java constant out of sync with C"); 12 | static_assert (TOX_MAX_FILENAME_LENGTH == 255, "Java constant out of sync with C"); 13 | static_assert (TOX_MAX_FRIEND_REQUEST_LENGTH == 1016, "Java constant out of sync with C"); 14 | static_assert (TOX_MAX_HOSTNAME_LENGTH == 255, "Java constant out of sync with C"); 15 | static_assert (TOX_MAX_MESSAGE_LENGTH == 1372, "Java constant out of sync with C"); 16 | static_assert (TOX_MAX_NAME_LENGTH == 128, "Java constant out of sync with C"); 17 | static_assert (TOX_MAX_STATUS_MESSAGE_LENGTH == 1007, "Java constant out of sync with C"); 18 | static_assert (TOX_PUBLIC_KEY_SIZE == 32, "Java constant out of sync with C"); 19 | static_assert (TOX_SECRET_KEY_SIZE == 32, "Java constant out of sync with C"); 20 | } 21 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/codegen/CodeGenerator.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni.codegen 2 | 3 | import java.io.{File, PrintWriter} 4 | 5 | import com.google.common.base.CaseFormat 6 | import gnieh.pp.PrettyRenderer 7 | import im.tox.tox4j.impl.jni.codegen.cxx.Ast._ 8 | import im.tox.tox4j.impl.jni.codegen.cxx.{Ast, Print} 9 | 10 | object NameConversions { 11 | 12 | def cxxVarName(name: String): String = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, name) 13 | def cxxTypeName(name: String): String = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, name) 14 | def javaVarName(name: String): String = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name) 15 | def javaTypeName(name: String): String = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name) 16 | 17 | } 18 | 19 | abstract class CodeGenerator extends App { 20 | 21 | def writeCode(path: String, sep: String = "\n\n")(code: Ast.TranslationUnit): Unit = { 22 | val renderer = new PrettyRenderer(130) 23 | 24 | val writer = new PrintWriter(new File("src/main/cpp", path)) 25 | try { 26 | writer.println(code.map(Print.printDecl).map(renderer).mkString(sep)) 27 | } finally { 28 | writer.close() 29 | } 30 | } 31 | 32 | def ifdef(header: String, guard: String, code: TranslationUnit*): TranslationUnit = { 33 | Include(header) +: 34 | Ifdef(guard) +: 35 | code.flatten :+ 36 | Endif 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFriendCustomPacketException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFriendCustomPacketException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * Attempted to send an empty packet. 11 | */ 12 | EMPTY, 13 | /** 14 | * This client is currently not connected to the friend. 15 | */ 16 | FRIEND_NOT_CONNECTED, 17 | /** 18 | * The friendNumber passed did not designate a valid friend. 19 | */ 20 | FRIEND_NOT_FOUND, 21 | /** 22 | * The first byte of data was not in the specified range for the packet type. 23 | * This range is 200-254 for lossy, and 160-191 for lossless packets. 24 | */ 25 | INVALID, 26 | /** 27 | * An argument was null. 28 | */ 29 | NULL, 30 | /** 31 | * An allocation error occurred while increasing the send queue size. 32 | */ 33 | SENDQ, 34 | /** 35 | * Packet data length exceeded {@link ToxCoreConstants#MAX_CUSTOM_PACKET_SIZE}. 36 | */ 37 | TOO_LONG, 38 | } 39 | 40 | public ToxFriendCustomPacketException(@NotNull Code code) { 41 | this(code, ""); 42 | } 43 | 44 | public ToxFriendCustomPacketException(@NotNull Code code, String message) { 45 | super(code, message); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/FriendNameCallbackTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxConnection 4 | import im.tox.tox4j.testing.autotest.{AliceBobTest, AliceBobTestBase} 5 | 6 | final class FriendNameCallbackTest extends AliceBobTest { 7 | 8 | override type State = Int 9 | override def initialState: State = 0 10 | 11 | protected override def newChatClient(name: String, expectedFriendName: String) = new ChatClient(name, expectedFriendName) { 12 | 13 | override def friendConnectionStatus(friendNumber: Int, connectionStatus: ToxConnection)(state: ChatState): ChatState = { 14 | super.friendConnectionStatus(friendNumber, connectionStatus)(state) 15 | if (connectionStatus != ToxConnection.NONE) { 16 | state.addTask { (tox, state) => 17 | tox.setName(selfName.getBytes) 18 | state 19 | } 20 | } else { 21 | state 22 | } 23 | } 24 | 25 | override def friendName(friendNumber: Int, name: Array[Byte])(state: ChatState): ChatState = { 26 | debug(s"friend changed name to: ${new String(name)}") 27 | assert(friendNumber == AliceBobTestBase.FriendNumber) 28 | 29 | state.get match { 30 | case 0 => 31 | assert(name.isEmpty) 32 | state.set(1) 33 | case 1 => 34 | assert(new String(name) == expectedFriendName) 35 | state.finish 36 | } 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/events/SendFileButtonOnAction.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.events 2 | 3 | import java.awt.event.{ActionEvent, ActionListener} 4 | import java.io.File 5 | import javax.swing._ 6 | 7 | import im.tox.gui.MainView 8 | import im.tox.tox4j.core.enums.ToxFileKind 9 | import im.tox.tox4j.core.exceptions.ToxFileSendException 10 | 11 | final class SendFileButtonOnAction(toxGui: MainView) extends ActionListener { 12 | 13 | override def actionPerformed(event: ActionEvent): Unit = { 14 | try { 15 | val friendNumber = toxGui.friendList.getSelectedIndex 16 | if (friendNumber == -1) { 17 | JOptionPane.showMessageDialog(toxGui, "Select a friend to send a message to") 18 | } 19 | 20 | val file = new File(toxGui.fileName.getText) 21 | if (!file.exists) { 22 | JOptionPane.showMessageDialog(toxGui, "File does not exist: " + file) 23 | } else { 24 | toxGui.fileModel.addOutgoing( 25 | friendNumber, 26 | file, 27 | toxGui.tox.fileSend( 28 | friendNumber, 29 | ToxFileKind.DATA, 30 | file.length, 31 | null, 32 | file.getName.getBytes 33 | ) 34 | ) 35 | } 36 | } catch { 37 | case e: ToxFileSendException => 38 | toxGui.addMessage("Send file failed: ", e.code) 39 | case e: Throwable => 40 | JOptionPane.showMessageDialog(toxGui, MainView.printExn(e)) 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: scala 2 | sudo: false 3 | 4 | addons: 5 | apt: 6 | sources: ['ubuntu-toolchain-r-test','llvm-toolchain-precise-3.5'] 7 | packages: ['clang-3.5', 'p7zip-full'] 8 | 9 | cache: 10 | directories: 11 | - $HOME/cache 12 | 13 | env: 14 | matrix: 15 | - TARGET=arm-linux-androideabi 16 | - TARGET=i686-linux-android 17 | - TARGET=host TEST_GOAL=coverage 18 | - TARGET=host TEST_GOAL=performance 19 | 20 | matrix: 21 | fast_finish: true 22 | allow_failures: 23 | - env: TARGET=host TEST_GOAL=performance 24 | 25 | install: 26 | # Move files from cache directory. 27 | - rm -rf $HOME/.ivy2 $HOME/.sbt $HOME/.usr 28 | - mkdir -p $HOME/cache/ivy2 $HOME/cache/sbt $HOME/cache/usr 29 | - ln -s $HOME/cache/ivy2 $HOME/.ivy2 30 | - ln -s $HOME/cache/sbt $HOME/.sbt 31 | - ln -s $HOME/cache/usr $HOME/.usr 32 | # Set-up step. 33 | - make setup-$TARGET TARGET=$TARGET 34 | 35 | script: 36 | # Build/install step. 37 | - make install GOAL=$TEST_GOAL 38 | 39 | before_cache: 40 | - ln -s $PWD/.git projects/tox4j/ 41 | - ln -s $PWD/projects/tox4j/src/main/java/* $PWD/projects/tox4j/ 42 | - if [ "$TEST_GOAL" = "coverage" ]; then cd projects/tox4j && sbt coveralls; fi 43 | # Clean up cache. 44 | - find $HOME/cache/ivy2 -type f -name "ivydata-*.properties" -delete 45 | - find $HOME/cache/ivy2 -type d -name "im.tox" -exec rm -rf {} ";" 46 | - find $HOME/cache/sbt/boot -name "sbt.*.lock" -delete 47 | 48 | branches: 49 | only: 50 | - master 51 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/enums/ToxavCallControl.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.enums; 2 | 3 | /** 4 | * Call control. 5 | */ 6 | public enum ToxavCallControl { 7 | /** 8 | * Resume a previously paused call. Only valid if the pause was caused by this 9 | * client, if not, this control is ignored. Not valid before the call is accepted. 10 | */ 11 | RESUME, 12 | 13 | /** 14 | * Put a call on hold. Not valid before the call is accepted. 15 | */ 16 | PAUSE, 17 | 18 | /** 19 | * Reject a call if it was not answered, yet. Cancel a call after it was 20 | * answered. 21 | */ 22 | CANCEL, 23 | 24 | /** 25 | * Request that the friend stops sending audio. Regardless of the friend's 26 | * compliance, this will cause the {@link im.tox.tox4j.av.callbacks.AudioReceiveFrameCallback} 27 | * event to stop being triggered on receiving an audio frame from the friend. 28 | */ 29 | MUTE_AUDIO, 30 | 31 | /** 32 | * Calling this control will notify client to start sending audio again. 33 | */ 34 | UNMUTE_AUDIO, 35 | 36 | /** 37 | * Request that the friend stops sending video. Regardless of the friend's 38 | * compliance, this will cause the {@link im.tox.tox4j.av.callbacks.VideoReceiveFrameCallback} 39 | * event to stop being triggered on receiving an video frame from the friend. 40 | */ 41 | HIDE_VIDEO, 42 | 43 | /** 44 | * Calling this control will notify client to start sending video again. 45 | */ 46 | SHOW_VIDEO, 47 | } 48 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/impl/jni/ToxCryptoJni.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni; 2 | 3 | @SuppressWarnings({"checkstyle:emptylineseparator", "checkstyle:linelength"}) 4 | public final class ToxCryptoJni { 5 | 6 | static { 7 | System.loadLibrary("tox4j"); 8 | } 9 | 10 | static native byte[] toxPassKeyEncrypt(byte[] data, byte[] passKey); 11 | static native byte[] toxGetSalt(byte[] data); 12 | static native boolean toxIsDataEncrypted(byte[] data); 13 | static native byte[] toxDeriveKeyWithSalt(byte[] passphrase, byte[] salt); 14 | static native byte[] toxDeriveKeyFromPass(byte[] passphrase); 15 | static native byte[] toxPassKeyDecrypt(byte[] data, byte[] passKey); 16 | static native byte[] toxHash(byte[] data); 17 | 18 | public static native void randombytes(byte[] buffer); 19 | public static native int cryptoBoxKeypair(byte[] publicKey, byte[] secretKey); 20 | public static native int cryptoBox(byte[] cipherText, byte[] plainText, byte[] nonce, byte[] publicKey, byte[] privateKey); 21 | public static native int cryptoBoxOpen(byte[] plainText, byte[] cipherText, byte[] nonce, byte[] publicKey, byte[] privateKey); 22 | public static native int cryptoBoxBeforenm(byte[] sharedKey, byte[] publicKey, byte[] privateKey); 23 | public static native int cryptoBoxAfternm(byte[] cipherText, byte[] plainText, byte[] nonce, byte[] sharedKey); 24 | public static native int cryptoBoxOpenAfternm(byte[] plainText, byte[] cipherText, byte[] nonce, byte[] sharedKey); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/bench/SettersTimingBench.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.bench 2 | 3 | import im.tox.tox4j.bench.PerformanceReportBase._ 4 | import im.tox.tox4j.bench.TimingReport 5 | import im.tox.tox4j.core.ToxCore 6 | import im.tox.tox4j.core.enums.ToxUserStatus 7 | 8 | final class SettersTimingBench extends TimingReport { 9 | 10 | timing of classOf[ToxCore[Unit]] in { 11 | 12 | measure method "setNoSpam" in { 13 | usingTox(iterations100k) in { 14 | case (sz, tox) => 15 | (0 until sz) foreach (i => tox.setNospam(i)) 16 | } 17 | } 18 | 19 | measure method "setName" in { 20 | usingTox(names, iterations10k) in { 21 | case (name, sz, tox) => 22 | (0 until sz) foreach (_ => tox.setName(name)) 23 | } 24 | } 25 | 26 | measure method "setStatusMessage" in { 27 | usingTox(statusMessages, iterations10k) in { 28 | case (statusMessage, sz, tox) => 29 | (0 until sz) foreach (_ => tox.setStatusMessage(statusMessage)) 30 | } 31 | } 32 | 33 | measure method "setStatus" in { 34 | usingTox(iterations10k) in { 35 | case (sz, tox) => 36 | (0 until sz) foreach (_ => tox.setStatus(ToxUserStatus.AWAY)) 37 | } 38 | } 39 | 40 | measure method "setTyping" in { 41 | usingTox(iterations10k) in { 42 | case (sz, tox) => 43 | (0 until sz) foreach (_ => tox.setTyping(0, typing = true)) 44 | } 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /tools/check-whitespace: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use File::Find; 5 | 6 | my %errors; 7 | 8 | sub e { 9 | my ($msg, $line) = @_; 10 | chomp $line; 11 | $errors{$File::Find::name}{$msg} = $line; 12 | } 13 | 14 | sub e_tab { 15 | my ($line) = @_; 16 | e "contains tab", $line; 17 | } 18 | 19 | sub e_ws_eol { 20 | my ($line) = @_; 21 | e "contains white-space at EOL", $line; 22 | } 23 | 24 | sub e_no_eol { 25 | my ($line) = @_; 26 | e "has no new-line at EOF", $line; 27 | } 28 | 29 | sub check(&) { 30 | my ($cb) = @_; 31 | sub { 32 | open my $fh, '<', $_[0] 33 | or die "Could not open $_[0] for reading: $!"; 34 | for my $line (<$fh>) { 35 | local $_ = $line; 36 | $cb->(); 37 | } 38 | } 39 | } 40 | 41 | *check_tab = check { e_tab $_ if /\t/ }; 42 | *check_ws_eol = check { e_ws_eol $_ if /\s\n/ }; 43 | *check_no_eol = check { e_no_eol $_ unless /\n$/ }; 44 | 45 | find { 46 | wanted => sub { 47 | check_ws_eol ($_); 48 | check_no_eol ($_); 49 | 50 | return if /^Makefile.*/ 51 | or $_ eq "CMakeLists.txt" 52 | or $_ eq "Build.lsp"; 53 | 54 | check_tab ($_); 55 | }, 56 | }, 'src'; 57 | 58 | if (%errors) { 59 | for my $file (sort keys %errors) { 60 | for my $msg (sort keys $errors{$file}) { 61 | my $line = $errors{$file}{$msg}; 62 | print "$file: error: file $msg\n"; 63 | print " at: '$line'\n"; 64 | } 65 | } 66 | 67 | exit 1 68 | } 69 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/MethodMap.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni 2 | 3 | import java.lang.reflect.{Method, Modifier} 4 | 5 | import im.tox.tox4j.impl.jni.codegen.NameConversions 6 | 7 | import scalaz.Scalaz._ 8 | 9 | object MethodMap { 10 | 11 | private val actions = Seq("get", "set", "add", "delete") 12 | 13 | private def removeSelf(name: Seq[String]): Seq[String] = { 14 | name.headOption match { 15 | case Some("self") => name.tail 16 | case _ => name 17 | } 18 | } 19 | 20 | private def moveActionToFront(name: Seq[String]): Seq[String] = { 21 | name.indexWhere(actions.contains) match { 22 | case -1 => 23 | name 24 | case actionIndex => 25 | name(actionIndex) +: (name.slice(0, actionIndex) ++ name.slice(actionIndex + 1, name.length)) 26 | } 27 | } 28 | 29 | def apply(jniClass: Class[_]): Map[String, Method] = { 30 | jniClass 31 | .getDeclaredMethods.toSeq 32 | .filter { method => 33 | Modifier.isNative(method.getModifiers) && 34 | method.getName.startsWith("tox") 35 | } 36 | .map { method => 37 | val expectedName = (method.getName 38 | |> NameConversions.cxxVarName 39 | |> (_.split("_").toSeq.tail) 40 | |> removeSelf 41 | |> moveActionToFront 42 | |> (_.mkString("_")) 43 | |> NameConversions.javaVarName) 44 | (expectedName, method) 45 | } |> { pairs => Map(pairs: _*) } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/codegen/JniMethodRefs.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni.codegen 2 | 3 | import java.lang.reflect.Modifier 4 | 5 | import im.tox.tox4j.impl.jni.codegen.NameConversions.cxxVarName 6 | import im.tox.tox4j.impl.jni.codegen.cxx.Ast._ 7 | import im.tox.tox4j.impl.jni.{ToxAvJni, ToxCoreJni, ToxCryptoJni} 8 | 9 | object JniMethodRefs extends CodeGenerator { 10 | 11 | def generateNativeDecls(clazz: Class[_]): TranslationUnit = { 12 | clazz.getDeclaredMethods 13 | .filter { method => 14 | Modifier.isNative(method.getModifiers) && 15 | !Seq("invoke", "tox4j").exists(method.getName.startsWith) 16 | } 17 | .sortBy(method => method.getName) 18 | .flatMap { method => 19 | Seq( 20 | MacroCall(FunCall(Identifier("JAVA_METHOD_REF"), Seq(Identifier(method.getName)))), 21 | MacroCall(FunCall(Identifier("CXX_FUNCTION_REF"), Seq(Identifier(cxxVarName(method.getName))))) 22 | ) 23 | } 24 | } 25 | 26 | writeCode("ToxAv/generated/natives.h", "\n") { 27 | Comment(classOf[ToxAvJni].getName) +: 28 | generateNativeDecls(classOf[ToxAvJni]) 29 | } 30 | 31 | writeCode("ToxCore/generated/natives.h", "\n") { 32 | Comment(classOf[ToxCoreJni].getName) +: 33 | generateNativeDecls(classOf[ToxCoreJni]) 34 | } 35 | 36 | writeCode("ToxCrypto/generated/natives.h", "\n") { 37 | Comment(classOf[ToxCryptoJni].getName) +: 38 | generateNativeDecls(classOf[ToxCryptoJni]) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /projects/linters/src/main/scala/im/tox/tox4j/lint/OptionOrNull.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.lint 2 | 3 | import org.brianmckenna.wartremover.{WartTraverser, WartUniverse} 4 | 5 | /** 6 | * Checks that [[Option.orNull]] is not used. This method is useful for Java 7 | * interoperability, but is generally unsafe, as it produces potentially null 8 | * values, giving the system opportunity to throw a [[NullPointerException]]. 9 | * 10 | * Code that interoperates with Java code will need to use [[SuppressWarnings]]. 11 | */ 12 | @SuppressWarnings(Array("org.brianmckenna.wartremover.warts.Any")) 13 | object OptionOrNull extends WartTraverser { 14 | 15 | val errorMessage = "Option#orNull is disabled" 16 | 17 | def apply(u: WartUniverse): u.universe.Traverser = { 18 | import u.universe._ 19 | 20 | val optionSymbol = rootMirror.staticClass(classOf[Option[_]].getName) 21 | val OrNullName = TermName("orNull") 22 | 23 | new u.Traverser { 24 | 25 | override def traverse(tree: Tree): Unit = { 26 | tree match { 27 | // Ignore trees marked by @SuppressWarnings 28 | case t: Tree if hasWartAnnotation(u)(t) => 29 | // TODO(iphydf): how is this reached? 30 | // case LabelDef(_, _, rhs) if isSynthetic(u)(tree) => 31 | 32 | case Select(left, OrNullName) if left.tpe.baseType(optionSymbol) != NoType => 33 | u.error(tree.pos, errorMessage) 34 | 35 | case _ => super.traverse(tree) 36 | } 37 | } 38 | 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/impl/jni/ToxCryptoImpl.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni 2 | 3 | import im.tox.tox4j.crypto.{ToxCrypto, ToxCryptoConstants} 4 | 5 | object ToxCryptoImpl extends ToxCrypto { 6 | 7 | override type PassKey = Array[Byte] 8 | 9 | override def passKeyEquals(a: PassKey, b: PassKey): Boolean = a.deep == b.deep 10 | override def passKeyToBytes(passKey: PassKey): Seq[Byte] = passKey 11 | 12 | override def passKeyFromBytes(bytes: Seq[Byte]): Option[PassKey] = { 13 | if (bytes.length == ToxCryptoConstants.KeyLength + ToxCryptoConstants.SaltLength) { 14 | Some(bytes.toArray) 15 | } else { 16 | None 17 | } 18 | } 19 | 20 | override def encrypt(data: Array[Byte], passKey: PassKey): Array[Byte] = 21 | ToxCryptoJni.toxPassKeyEncrypt(data, passKey) 22 | override def getSalt(data: Array[Byte]): Array[Byte] = 23 | ToxCryptoJni.toxGetSalt(data) 24 | override def isDataEncrypted(data: Array[Byte]): Boolean = 25 | ToxCryptoJni.toxIsDataEncrypted(data) 26 | override def deriveKeyWithSalt(passphrase: Array[Byte], salt: Array[Byte]): PassKey = 27 | ToxCryptoJni.toxDeriveKeyWithSalt(passphrase, salt) 28 | override def deriveKeyFromPass(passphrase: Array[Byte]): PassKey = 29 | ToxCryptoJni.toxDeriveKeyFromPass(passphrase) 30 | override def decrypt(data: Array[Byte], passKey: PassKey): Array[Byte] = 31 | ToxCryptoJni.toxPassKeyDecrypt(data, passKey) 32 | override def hash(data: Array[Byte]): Array[Byte] = 33 | ToxCryptoJni.toxHash(data) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/av/exceptions/ToxavSendFrameException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxavSendFrameException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * The friend number did not designate a valid friend. 11 | */ 12 | FRIEND_NOT_FOUND, 13 | /** 14 | * This client is currently not in a call with the friend. 15 | */ 16 | FRIEND_NOT_IN_CALL, 17 | /** 18 | * One or more of the frame parameters was invalid. E.g. the resolution may be too 19 | * small or too large, or the audio sampling rate may be unsupported. 20 | */ 21 | INVALID, 22 | /** 23 | * In case of video, one of Y, U, or V was NULL. In case of audio, the samples 24 | * data pointer was NULL. 25 | */ 26 | NULL, 27 | /** 28 | * Either friend turned off audio or video receiving or we turned off sending 29 | * for the said payload. 30 | */ 31 | PAYLOAD_TYPE_DISABLED, 32 | /** 33 | * Failed to push frame through rtp interface. 34 | */ 35 | RTP_FAILED, 36 | /** 37 | * Synchronization error occurred. 38 | */ 39 | SYNC, 40 | } 41 | 42 | public ToxavSendFrameException(@NotNull Code code) { 43 | this(code, ""); 44 | } 45 | 46 | public ToxavSendFrameException(@NotNull Code code, String message) { 47 | super(code, message); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/ocaml/core/message.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | 4 | type cipher 5 | type plain 6 | 7 | type ('encryption, 'access, 'seek) t = ('access, 'seek) Iobuf.t 8 | 9 | 10 | let cipher () = Iobuf.create Async.Std.Udp.default_capacity 11 | let plain () = Iobuf.create Async.Std.Udp.default_capacity 12 | 13 | let cipher_of_string = Iobuf.of_string 14 | let plain_of_string = Iobuf.of_string 15 | 16 | let of_iobuf = Iobuf.read_only 17 | let to_iobuf = Iobuf.read_only 18 | 19 | let flip_lo = Iobuf.flip_lo 20 | 21 | let to_string = Iobuf.to_string 22 | 23 | 24 | module type Accessor = sig 25 | type ('encryption, 'a) t 26 | 27 | val uint8 : ('encryption, int ) t 28 | val uint16_be : ('encryption, int ) t 29 | val int64_t_be : ('encryption, int64 ) t 30 | val string : ?str_pos:int -> ?len:int 31 | -> ('encryption, string) t 32 | end 33 | 34 | 35 | module Consume = struct 36 | type 'encryption src = ('encryption, read_only, Iobuf.seek) t 37 | type ('encryption, 'a) t = 'encryption src -> 'a 38 | 39 | open Iobuf.Consume 40 | let uint8 = uint8 41 | let uint16_be = uint16_be 42 | let int64_t_be = int64_t_be 43 | let string = string 44 | end 45 | 46 | 47 | module Fill = struct 48 | type 'encryption src = ('encryption, read_write, Iobuf.seek) t 49 | type ('encryption, 'a) t = 'encryption src -> 'a -> unit 50 | 51 | open Iobuf.Fill 52 | let uint8 = uint8 53 | let uint16_be = uint16_be 54 | let int64_t_be = int64_t_be 55 | let string = string 56 | end 57 | -------------------------------------------------------------------------------- /projects/tox4j/tools/cmake/FindGlog.cmake: -------------------------------------------------------------------------------- 1 | # From https://github.com/hanjianwei/cmake-modules/blob/master/FindGlog.cmake 2 | # 3 | # - Try to find Glog 4 | # 5 | # The following variables are optionally searched for defaults 6 | # GLOG_ROOT_DIR: Base directory where all GLOG components are found 7 | # 8 | # The following are set after configuration is done: 9 | # GLOG_FOUND 10 | # GLOG_INCLUDE_DIRS 11 | # GLOG_LIBRARIES 12 | 13 | include(FindPackageHandleStandardArgs) 14 | 15 | set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog") 16 | 17 | if(WIN32) 18 | find_path(GLOG_INCLUDE_DIR glog/logging.h 19 | PATHS ${GLOG_ROOT_DIR}/src/windows) 20 | else() 21 | find_path(GLOG_INCLUDE_DIR glog/logging.h 22 | PATHS ${GLOG_ROOT_DIR}) 23 | endif() 24 | 25 | if(MSVC) 26 | find_library(GLOG_LIBRARY_RELEASE libglog_static 27 | PATHS ${GLOG_ROOT_DIR} 28 | PATH_SUFFIXES Release) 29 | 30 | find_library(GLOG_LIBRARY_DEBUG libglog_static 31 | PATHS ${GLOG_ROOT_DIR} 32 | PATH_SUFFIXES Debug) 33 | 34 | set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG}) 35 | else() 36 | find_library(GLOG_LIBRARY glog 37 | PATHS ${GLOG_ROOT_DIR} 38 | PATH_SUFFIXES 39 | lib 40 | lib64) 41 | endif() 42 | 43 | find_package_handle_standard_args(GLOG DEFAULT_MSG 44 | GLOG_INCLUDE_DIR GLOG_LIBRARY) 45 | 46 | if(GLOG_FOUND) 47 | set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) 48 | set(GLOG_LIBRARIES ${GLOG_LIBRARY}) 49 | endif() 50 | -------------------------------------------------------------------------------- /projects/build-basic/src/main/scala/sbt/tox4j/MakeScripts.scala: -------------------------------------------------------------------------------- 1 | package sbt.tox4j 2 | 3 | import sbt.Keys._ 4 | import sbt._ 5 | 6 | object MakeScripts extends AutoPlugin { 7 | 8 | override def trigger: PluginTrigger = allRequirements 9 | 10 | object Keys { 11 | val makeScripts = TaskKey[Unit]("makeScripts") 12 | } 13 | 14 | import Keys._ 15 | 16 | private def classBaseName(s: String): String = { 17 | val lastDot = s.lastIndexOf('.') 18 | if (lastDot == -1) { 19 | s 20 | } else { 21 | s.substring(lastDot + 1) 22 | } 23 | } 24 | 25 | private def makeScriptsTask(base: File, opts: Seq[String], cp: Classpath, mains: Seq[String]) = { 26 | val template = 27 | """#!/usr/bin/env perl 28 | |my @CLASSPATH = ( 29 | | "%s" 30 | |); 31 | |exec "java", 32 | | "%s", 33 | | "-classpath", (join ":", @CLASSPATH), 34 | | "%s", @ARGV 35 | |""".stripMargin 36 | for (main <- mains) { 37 | val contents = template.format( 38 | cp.files.get.mkString("\",\n \""), 39 | opts.mkString("\",\n \""), 40 | main 41 | ) 42 | val out = base / "bin" / classBaseName(main) 43 | IO.write(out, contents) 44 | out.setExecutable(true) 45 | } 46 | } 47 | 48 | override val projectSettings: Seq[Setting[_]] = { 49 | makeScripts <<= ( 50 | baseDirectory, 51 | javaOptions in Test, 52 | fullClasspath in Test, 53 | discoveredMainClasses in Test 54 | ) map makeScriptsTask 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/FriendStatusMessageCallbackTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxConnection 4 | import im.tox.tox4j.testing.autotest.{AliceBobTest, AliceBobTestBase} 5 | 6 | final class FriendStatusMessageCallbackTest extends AliceBobTest { 7 | 8 | override type State = Int 9 | override def initialState: State = 0 10 | 11 | protected override def newChatClient(name: String, expectedFriendName: String) = new ChatClient(name, expectedFriendName) { 12 | 13 | override def friendConnectionStatus(friendNumber: Int, connectionStatus: ToxConnection)(state: ChatState): ChatState = { 14 | super.friendConnectionStatus(friendNumber, connectionStatus)(state) 15 | if (connectionStatus != ToxConnection.NONE) { 16 | state.addTask { (tox, state) => 17 | tox.setStatusMessage(s"I like $expectedFriendName".getBytes) 18 | state 19 | } 20 | } else { 21 | state 22 | } 23 | } 24 | 25 | override def friendStatusMessage(friendNumber: Int, message: Array[Byte])(state: ChatState): ChatState = { 26 | debug(s"friend changed status message to: ${new String(message)}") 27 | assert(friendNumber == AliceBobTestBase.FriendNumber) 28 | 29 | state.get match { 30 | case 0 => 31 | assert(message.isEmpty) 32 | state.set(1) 33 | case 1 => 34 | assert(new String(message) == s"I like $selfName") 35 | state.finish 36 | } 37 | } 38 | } 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/cpp/util/wrap_void.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | /** 7 | * Helper template to capture the return value of a function call so that 8 | * functions returning void can be treated the same way as non-void ones. 9 | * 10 | * Both contain an unwrap member function with the return type of the called 11 | * function. This can be used in other function templates returning some T 12 | * that can be void. 13 | * 14 | * T must be movable or copyable for this to work. Also, all the arguments 15 | * must be copyable. 16 | */ 17 | template 18 | struct wrapped_value 19 | { 20 | T value; 21 | T unwrap () { return std::move (value); } 22 | 23 | template 24 | static wrapped_value 25 | wrap (FuncT func, Args ...args) 26 | { 27 | return { func (args...) }; 28 | } 29 | }; 30 | 31 | 32 | template<> 33 | struct wrapped_value 34 | { 35 | void unwrap () const { } 36 | 37 | template 38 | static wrapped_value 39 | wrap (FuncT func, Args ...args) 40 | { 41 | func (args...); 42 | return { }; 43 | } 44 | }; 45 | 46 | 47 | /** 48 | * Call this with the function and its arguments to wrap the return value in 49 | * a wrapped_value class. 50 | */ 51 | template 52 | wrapped_value::type> 53 | wrap_void (FuncT func, Args ...args) 54 | { 55 | return wrapped_value< 56 | typename std::result_of::type 57 | >::wrap (func, args...); 58 | } 59 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/gui/events/SendButtonOnAction.scala: -------------------------------------------------------------------------------- 1 | package im.tox.gui.events 2 | 3 | import java.awt.event.{ActionEvent, ActionListener} 4 | import javax.swing._ 5 | 6 | import im.tox.gui.MainView 7 | import im.tox.tox4j.core.enums.ToxMessageType 8 | import im.tox.tox4j.core.exceptions.ToxFriendSendMessageException 9 | 10 | final class SendButtonOnAction(toxGui: MainView) extends ActionListener { 11 | 12 | override def actionPerformed(event: ActionEvent): Unit = { 13 | try { 14 | val friendNumber = toxGui.friendList.getSelectedIndex 15 | if (friendNumber == -1) { 16 | JOptionPane.showMessageDialog(toxGui, "Select a friend to send a message to") 17 | } 18 | 19 | if (toxGui.messageRadioButton.isSelected) { 20 | toxGui.tox.friendSendMessage(friendNumber, ToxMessageType.NORMAL, 0, toxGui.messageText.getText.getBytes) 21 | toxGui.addMessage("Sent message to ", friendNumber + ": " + toxGui.messageText.getText) 22 | } else if (toxGui.actionRadioButton.isSelected) { 23 | toxGui.tox.friendSendMessage(friendNumber, ToxMessageType.ACTION, 0, toxGui.messageText.getText.getBytes) 24 | toxGui.addMessage("Sent action to ", friendNumber + ": " + toxGui.messageText.getText) 25 | } 26 | 27 | toxGui.messageText.setText("") 28 | } catch { 29 | case e: ToxFriendSendMessageException => 30 | toxGui.addMessage("Send message failed: ", e.code) 31 | case e: Throwable => 32 | JOptionPane.showMessageDialog(toxGui, MainView.printExn(e)) 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/FilePauseResumeWithResendTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.ToxCore 4 | import im.tox.tox4j.core.enums.{ToxFileControl, ToxFileKind} 5 | 6 | final class FilePauseResumeWithResendTest extends FilePauseResumeTestBase { 7 | 8 | protected override def newChatClient(name: String, expectedFriendName: String) = new Alice(name, expectedFriendName) 9 | 10 | final class Alice(name: String, expectedFriendName: String) extends super.Alice(name, expectedFriendName) { 11 | 12 | protected override def addFileRecvTask(friendNumber: Int, fileNumber: Int, bobSentFileNumber: Int, bobOffset: Long, tox: ToxCore[ChatState]): Unit = { 13 | debug(s"seek file to $bobOffset") 14 | tox.fileSeek(friendNumber, bobSentFileNumber, bobOffset) 15 | bobShouldPause = 1 16 | debug(s"sending control RESUME for $fileNumber") 17 | tox.fileControl(friendNumber, fileNumber, ToxFileControl.RESUME) 18 | } 19 | 20 | protected override def addFriendMessageTask(friendNumber: Int, bobSentFileNumber: Int, fileId: Array[Byte], tox: ToxCore[ChatState]): Unit = { 21 | if (isAlice) { 22 | aliceSentFileNumber = tox.fileSend(friendNumber, ToxFileKind.DATA, fileData.length, fileId, ("file for " + expectedFriendName + ".png").getBytes) 23 | aliceShouldPause = 1 24 | } else { 25 | debug("Send resume file transmission control") 26 | tox.fileControl(friendNumber, bobSentFileNumber, ToxFileControl.RESUME) 27 | } 28 | } 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/FriendLossyPacketCallbackTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxConnection 4 | import im.tox.tox4j.testing.autotest.{AliceBobTest, AliceBobTestBase} 5 | 6 | final class FriendLossyPacketCallbackTest extends AliceBobTest { 7 | 8 | override type State = Unit 9 | override def initialState: State = () 10 | 11 | protected override def newChatClient(name: String, expectedFriendName: String) = new ChatClient(name, expectedFriendName) { 12 | 13 | override def friendConnectionStatus(friendNumber: Int, connectionStatus: ToxConnection)(state: ChatState): ChatState = { 14 | super.friendConnectionStatus(friendNumber, connectionStatus)(state) 15 | if (connectionStatus != ToxConnection.NONE) { 16 | state.addTask { (tox, state) => 17 | val packet = s"_My name is $selfName".getBytes 18 | packet(0) = 200.toByte 19 | tox.friendSendLossyPacket(friendNumber, packet) 20 | state 21 | } 22 | } else { 23 | state 24 | } 25 | } 26 | 27 | override def friendLossyPacket(friendNumber: Int, packet: Array[Byte])(state: ChatState): ChatState = { 28 | val message = new String(packet, 1, packet.length - 1) 29 | debug(s"received a lossy packet[id=${packet(0)}]: $message") 30 | assert(friendNumber == AliceBobTestBase.FriendNumber) 31 | assert(packet(0) == 200.toByte) 32 | assert(message == s"My name is $expectedFriendName") 33 | state.finish 34 | } 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/core/callbacks/FriendLosslessPacketCallbackTest.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.callbacks 2 | 3 | import im.tox.tox4j.core.enums.ToxConnection 4 | import im.tox.tox4j.testing.autotest.{AliceBobTest, AliceBobTestBase} 5 | 6 | final class FriendLosslessPacketCallbackTest extends AliceBobTest { 7 | 8 | override type State = Unit 9 | override def initialState: State = () 10 | 11 | protected override def newChatClient(name: String, expectedFriendName: String) = new ChatClient(name, expectedFriendName) { 12 | 13 | override def friendConnectionStatus(friendNumber: Int, connectionStatus: ToxConnection)(state: ChatState): ChatState = { 14 | super.friendConnectionStatus(friendNumber, connectionStatus)(state) 15 | if (connectionStatus != ToxConnection.NONE) { 16 | state.addTask { (tox, state) => 17 | val packet = s"_My name is $selfName".getBytes 18 | packet(0) = 160.toByte 19 | tox.friendSendLosslessPacket(friendNumber, packet) 20 | state 21 | } 22 | } else { 23 | state 24 | } 25 | } 26 | 27 | override def friendLosslessPacket(friendNumber: Int, packet: Array[Byte])(state: ChatState): ChatState = { 28 | val message = new String(packet, 1, packet.length - 1) 29 | debug(s"received a lossless packet[id=${packet(0)}]: $message") 30 | assert(friendNumber == AliceBobTestBase.FriendNumber) 31 | assert(packet(0) == 160.toByte) 32 | assert(message == s"My name is $expectedFriendName") 33 | state.finish 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/impl/jni/codegen/JniConstants.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.impl.jni.codegen 2 | 3 | import im.tox.tox4j.core.ToxCoreConstants 4 | import im.tox.tox4j.crypto.ToxCryptoConstants 5 | import im.tox.tox4j.impl.jni.codegen.NameConversions.cxxTypeName 6 | import im.tox.tox4j.impl.jni.codegen.cxx.Ast._ 7 | 8 | object JniConstants extends CodeGenerator { 9 | 10 | def generateNativeDecls[T](prefix: String, constants: T): Decl = { 11 | val clazz = constants.getClass 12 | 13 | Fun( 14 | returnType = Type.void, 15 | name = "check" + clazz.getSimpleName.replace("$", ""), 16 | params = Seq(), 17 | body = CompoundStmt( 18 | body = clazz.getDeclaredMethods 19 | .sortBy(method => method.getName) 20 | .map { method => 21 | val value = method.invoke(constants).asInstanceOf[Int] 22 | ExprStmt(FunCall(Identifier("static_assert"), Seq( 23 | Equals(Identifier(prefix + cxxTypeName(method.getName)), IntegerLiteral(value)), 24 | StringLiteral("Java constant out of sync with C") 25 | ))) 26 | }.toSeq 27 | ) 28 | ) 29 | } 30 | 31 | writeCode("ToxCore/generated/constants.h", "\n") { 32 | Seq( 33 | Comment(ToxCoreConstants.getClass.getName), 34 | generateNativeDecls("TOX_", ToxCoreConstants) 35 | ) 36 | } 37 | 38 | writeCode("ToxCrypto/generated/constants.h", "\n") { 39 | Seq( 40 | Comment(ToxCryptoConstants.getClass.getName), 41 | generateNativeDecls("TOX_PASS_", ToxCryptoConstants) 42 | ) 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/exceptions/ToxFileControlException.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.exceptions; 2 | 3 | import im.tox.tox4j.exceptions.ToxException; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public final class ToxFileControlException extends ToxException { 7 | 8 | public enum Code { 9 | /** 10 | * A {@link ToxFileControl#PAUSE} control was sent, but the file transfer was already paused. 11 | */ 12 | ALREADY_PAUSED, 13 | /** 14 | * A {@link ToxFileControl#RESUME} control was sent, but the file transfer was paused by the other 15 | * party. Only the party that paused the transfer can resume it. 16 | */ 17 | DENIED, 18 | /** 19 | * This client is currently not connected to the friend. 20 | */ 21 | FRIEND_NOT_CONNECTED, 22 | /** 23 | * The friendNumber passed did not designate a valid friend. 24 | */ 25 | FRIEND_NOT_FOUND, 26 | /** 27 | * No file transfer with the given file number was found for the given friend. 28 | */ 29 | NOT_FOUND, 30 | /** 31 | * A {@link ToxFileControl#RESUME} control was sent, but the file transfer is running normally. 32 | */ 33 | NOT_PAUSED, 34 | /** 35 | * An allocation error occurred while increasing the send queue size. 36 | */ 37 | SENDQ, 38 | } 39 | 40 | public ToxFileControlException(@NotNull Code code) { 41 | this(code, ""); 42 | } 43 | 44 | public ToxFileControlException(@NotNull Code code, String message) { 45 | super(code, message); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/core/enums/ToxFileKind.java: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.core.enums; 2 | 3 | import im.tox.tox4j.core.ToxCoreConstants; 4 | import im.tox.tox4j.crypto.ToxCryptoConstants; 5 | 6 | public final class ToxFileKind { 7 | /** 8 | * Arbitrary file data. Clients can choose to handle it based on the file name 9 | * or magic or any other way they choose. 10 | */ 11 | public static final int DATA = 0; 12 | /** 13 | * Avatar image data. 14 | * 15 | *

16 | * Avatars can be sent at any time the client wishes. Generally, a client will 17 | * send the avatar to a friend when that friend comes online, and to all 18 | * friends when the avatar changed. A client can save some traffic by 19 | * remembering which friend received the updated avatar already and only send 20 | * it if the friend has an out of date avatar. 21 | * 22 | *

23 | * Clients who receive avatar send requests can reject it (by sending 24 | * {@link FileControl#CANCEL} before any other controls), or accept it 25 | * (by sending {@link FileControl#RESUME}). 26 | * The file_id of length {@link ToxCryptoConstants#HASH_LENGTH} bytes (same 27 | * length as {@link ToxCoreConstants#FILE_ID_LENGTH}) will contain the hash. 28 | * A client can compare this hash with a saved hash and send 29 | * {@link FileControl#CANCEL} to terminate the avatar transfer if it matches. 30 | * 31 | *

32 | * When fileSize is set to 0 in the transfer request it means that the client 33 | * has no avatar. 34 | */ 35 | public static final int AVATAR = 1; 36 | } 37 | -------------------------------------------------------------------------------- /projects/tox4j/src/test/java/im/tox/tox4j/av/bench/AvCallbackTimingBench.scala: -------------------------------------------------------------------------------- 1 | package im.tox.tox4j.av.bench 2 | 3 | import im.tox.tox4j.av.ToxAv 4 | import im.tox.tox4j.bench.PerformanceReportBase._ 5 | import im.tox.tox4j.bench.TimingReport 6 | import im.tox.tox4j.core.ToxCoreConstants 7 | import im.tox.tox4j.impl.jni.ToxAvImpl 8 | 9 | final class AvCallbackTimingBench extends TimingReport { 10 | 11 | val publicKey = Array.ofDim[Byte](ToxCoreConstants.PublicKeySize) 12 | val data = Array.ofDim[Byte](ToxCoreConstants.MaxCustomPacketSize) 13 | 14 | def invokePerformance(method: String, f: ToxAvImpl[Unit] => Unit): Unit = { 15 | performance of method in { 16 | usingToxAv(iterations1k) in { 17 | case (sz, toxAv: ToxAvImpl[Unit]) => 18 | (0 until sz) foreach { _ => 19 | f(toxAv) 20 | toxAv.iterate(()) 21 | } 22 | } 23 | } 24 | } 25 | 26 | timing of classOf[ToxAv[Unit]] in { 27 | 28 | val pcm = range("samples")(100).map(Array.ofDim[Short]) 29 | 30 | // invokePerformance("invokeAudioBitRateStatus", _.invokeAudioBitRateStatus(1, stable = true, 1)) 31 | // invokePerformance("invokeAudioReceiveFrame", _.invokeAudioReceiveFrame(1, pcm, 1, 1)) 32 | 33 | performance of "invokeAudioReceiveFrame" in { 34 | usingToxAv(iterations1k, pcm) in { 35 | case (sz, pcm: Array[Short], toxAv: ToxAvImpl[Unit]) => 36 | (0 until sz) foreach { _ => 37 | toxAv.invokeAudioReceiveFrame(1, pcm, 1, 1) 38 | toxAv.iterate(()) 39 | } 40 | } 41 | } 42 | 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /projects/tox4j/src/main/java/im/tox/tox4j/mkexceptions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use strict; 4 | use warnings FATAL => 'all'; 5 | use utf8; 6 | 7 | use JSON::PP; 8 | 9 | my $data = do { local $/; open my $fh, '<', 'exceptions.json' or die $!; decode_json <$fh> }; 10 | 11 | my $package = $data->[0]; 12 | my $prefix = $data->[1]; 13 | my $exns = $data->[2]; 14 | 15 | for my $type (keys %$exns) { 16 | for (keys $exns->{$type}) { 17 | my @lines = @{ $exns->{$type}{$_} }; 18 | s/^/ * / for @lines; 19 | $exns->{$type}{$_} = join "\n", @lines; 20 | } 21 | } 22 | 23 | for my $type (keys %$exns) { 24 | open my $fh, '>', "Tox${prefix}${type}Exception.java" 25 | or die $!; 26 | 27 | my $codes = 28 | join ",\n", 29 | map { " /**\n$exns->{$type}{$_}\n */\n $_" } 30 | (sort keys $exns->{$type}); 31 | 32 | my $JavaOnly = 33 | $codes =~ /\@JavaOnly/ 34 | ? "import im.tox.tox4j.exceptions.JavaOnly;\n" 35 | : ""; 36 | 37 | print $fh < { 44 | 45 | public enum Code { 46 | $codes, 47 | } 48 | 49 | public Tox${prefix}${type}Exception(\@NotNull Code code) { 50 | this(code, ""); 51 | } 52 | 53 | public Tox${prefix}${type}Exception(\@NotNull Code code, String message) { 54 | super(code, message); 55 | } 56 | 57 | } 58 | JAVA 59 | 60 | } 61 | --------------------------------------------------------------------------------