README.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. Introduction
  2. ============
  3. Matrix is an ambitious new ecosystem for open federated Instant Messaging and
  4. VoIP. The basics you need to know to get up and running are:
  5. - Everything in Matrix happens in a room. Rooms are distributed and do not
  6. exist on any single server. Rooms can be located using convenience aliases
  7. like ``#matrix:matrix.org`` or ``#test:localhost:8448``.
  8. - Matrix user IDs look like ``@matthew:matrix.org`` (although in the future
  9. you will normally refer to yourself and others using a 3PID: email
  10. address, phone number, etc rather than manipulating Matrix user IDs)
  11. The overall architecture is::
  12. client <----> homeserver <=====================> homeserver <----> client
  13. https://somewhere.org/_matrix https://elsewhere.net/_matrix
  14. ``#matrix:matrix.org`` is the official support room for Matrix, and can be
  15. accessed by the web client at http://matrix.org/alpha or via an IRC bridge at
  16. irc://irc.freenode.net/matrix.
  17. Synapse is currently in rapid development, but as of version 0.5 we believe it
  18. is sufficiently stable to be run as an internet-facing service for real usage!
  19. About Matrix
  20. ============
  21. Matrix specifies a set of pragmatic RESTful HTTP JSON APIs as an open standard,
  22. which handle:
  23. - Creating and managing fully distributed chat rooms with no
  24. single points of control or failure
  25. - Eventually-consistent cryptographically secure synchronisation of room
  26. state across a global open network of federated servers and services
  27. - Sending and receiving extensible messages in a room with (optional)
  28. end-to-end encryption[1]
  29. - Inviting, joining, leaving, kicking, banning room members
  30. - Managing user accounts (registration, login, logout)
  31. - Using 3rd Party IDs (3PIDs) such as email addresses, phone numbers,
  32. Facebook accounts to authenticate, identify and discover users on Matrix.
  33. - Placing 1:1 VoIP and Video calls
  34. These APIs are intended to be implemented on a wide range of servers, services
  35. and clients, letting developers build messaging and VoIP functionality on top
  36. of the entirely open Matrix ecosystem rather than using closed or proprietary
  37. solutions. The hope is for Matrix to act as the building blocks for a new
  38. generation of fully open and interoperable messaging and VoIP apps for the
  39. internet.
  40. Synapse is a reference "homeserver" implementation of Matrix from the core
  41. development team at matrix.org, written in Python/Twisted for clarity and
  42. simplicity. It is intended to showcase the concept of Matrix and let folks see
  43. the spec in the context of a codebase and let you run your own homeserver and
  44. generally help bootstrap the ecosystem.
  45. In Matrix, every user runs one or more Matrix clients, which connect through to
  46. a Matrix homeserver which stores all their personal chat history and user
  47. account information - much as a mail client connects through to an IMAP/SMTP
  48. server. Just like email, you can either run your own Matrix homeserver and
  49. control and own your own communications and history or use one hosted by
  50. someone else (e.g. matrix.org) - there is no single point of control or
  51. mandatory service provider in Matrix, unlike WhatsApp, Facebook, Hangouts, etc.
  52. Synapse ships with two basic demo Matrix clients: webclient (a basic group chat
  53. web client demo implemented in AngularJS) and cmdclient (a basic Python
  54. command line utility which lets you easily see what the JSON APIs are up to).
  55. Meanwhile, iOS and Android SDKs and clients are currently in development and available from:
  56. - https://github.com/matrix-org/matrix-ios-sdk
  57. - https://github.com/matrix-org/matrix-android-sdk
  58. We'd like to invite you to join #matrix:matrix.org (via http://matrix.org/alpha), run a homeserver, take a look at the Matrix spec at
  59. http://matrix.org/docs/spec, experiment with the APIs and the demo
  60. clients, and report any bugs via http://matrix.org/jira.
  61. Thanks for using Matrix!
  62. [1] End-to-end encryption is currently in development
  63. Homeserver Installation
  64. =======================
  65. System requirements:
  66. - POSIX-compliant system (tested on Linux & OSX)
  67. - Python 2.7
  68. Synapse is written in python but some of the libraries is uses are written in
  69. C. So before we can install synapse itself we need a working C compiler and the
  70. header files for python C extensions.
  71. Installing prerequisites on Ubuntu or Debian::
  72. $ sudo apt-get install build-essential python2.7-dev libffi-dev \
  73. python-pip python-setuptools sqlite3 \
  74. libssl-dev python-virtualenv libjpeg-dev
  75. Installing prerequisites on ArchLinux::
  76. $ sudo pacman -S base-devel python2 python-pip \
  77. python-setuptools python-virtualenv sqlite3
  78. Installing prerequisites on Mac OS X::
  79. $ xcode-select --install
  80. $ sudo pip install virtualenv
  81. To install the synapse homeserver run::
  82. $ virtualenv ~/.synapse
  83. $ source ~/.synapse/bin/activate
  84. $ pip install --process-dependency-links https://github.com/matrix-org/synapse/tarball/master
  85. This installs synapse, along with the libraries it uses, into a virtual
  86. environment under ``~/.synapse``.
  87. To set up your homeserver, run (in your virtualenv, as before)::
  88. $ python -m synapse.app.homeserver \
  89. --server-name machine.my.domain.name \
  90. --config-path homeserver.yaml \
  91. --generate-config
  92. Substituting your host and domain name as appropriate.
  93. For reliable VoIP calls to be routed via this homeserver, you MUST configure
  94. a TURN server. See docs/turn-howto.rst for details.
  95. Troubleshooting Installation
  96. ----------------------------
  97. Synapse requires pip 1.7 or later, so if your OS provides too old a version and
  98. you get errors about ``error: no such option: --process-dependency-links`` you
  99. may need to manually upgrade it::
  100. $ sudo pip install --upgrade pip
  101. If pip crashes mid-installation for reason (e.g. lost terminal), pip may
  102. refuse to run until you remove the temporary installation directory it
  103. created. To reset the installation::
  104. $ rm -rf /tmp/pip_install_matrix
  105. pip seems to leak *lots* of memory during installation. For instance, a Linux
  106. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  107. happens, you will have to individually install the dependencies which are
  108. failing, e.g.::
  109. $ pip install twisted
  110. On OSX, if you encounter clang: error: unknown argument: '-mno-fused-madd' you
  111. will need to export CFLAGS=-Qunused-arguments.
  112. ArchLinux
  113. ---------
  114. Installation on ArchLinux may encounter a few hiccups as Arch defaults to
  115. python 3, but synapse currently assumes python 2.7 by default.
  116. pip may be outdated (6.0.7-1 and needs to be upgraded to 6.0.8-1 )::
  117. $ sudo pip2.7 install --upgrade pip
  118. You also may need to explicitly specify python 2.7 again during the install
  119. request::
  120. $ pip2.7 install --process-dependency-links \
  121. https://github.com/matrix-org/synapse/tarball/master
  122. If you encounter an error with lib bcrypt causing an Wrong ELF Class:
  123. ELFCLASS32 (x64 Systems), you may need to reinstall py-bcrypt to correctly
  124. compile it under the right architecture. (This should not be needed if
  125. installing under virtualenv)::
  126. $ sudo pip2.7 uninstall py-bcrypt
  127. $ sudo pip2.7 install py-bcrypt
  128. During setup of homeserver you need to call python2.7 directly again::
  129. $ python2.7 -m synapse.app.homeserver \
  130. --server-name machine.my.domain.name \
  131. --config-path homeserver.yaml \
  132. --generate-config
  133. ...substituting your host and domain name as appropriate.
  134. Windows Install
  135. ---------------
  136. Synapse can be installed on Cygwin. It requires the following Cygwin packages:
  137. - gcc
  138. - git
  139. - libffi-devel
  140. - openssl (and openssl-devel, python-openssl)
  141. - python
  142. - python-setuptools
  143. The content repository requires additional packages and will be unable to process
  144. uploads without them:
  145. - libjpeg8
  146. - libjpeg8-devel
  147. - zlib
  148. If you choose to install Synapse without these packages, you will need to reinstall
  149. ``pillow`` for changes to be applied, e.g. ``pip uninstall pillow`` ``pip install
  150. pillow --user``
  151. Troubleshooting:
  152. - You may need to upgrade ``setuptools`` to get this to work correctly:
  153. ``pip install setuptools --upgrade``.
  154. - You may encounter errors indicating that ``ffi.h`` is missing, even with
  155. ``libffi-devel`` installed. If you do, copy the ``.h`` files:
  156. ``cp /usr/lib/libffi-3.0.13/include/*.h /usr/include``
  157. - You may need to install libsodium from source in order to install PyNacl. If
  158. you do, you may need to create a symlink to ``libsodium.a`` so ``ld`` can find
  159. it: ``ln -s /usr/local/lib/libsodium.a /usr/lib/libsodium.a``
  160. Running Your Homeserver
  161. =======================
  162. To actually run your new homeserver, pick a working directory for Synapse to run
  163. (e.g. ``~/.synapse``), and::
  164. $ cd ~/.synapse
  165. $ source ./bin/activate
  166. $ synctl start
  167. Troubleshooting Running
  168. -----------------------
  169. If synapse fails with ``missing "sodium.h"`` crypto errors, you may need
  170. to manually upgrade PyNaCL, as synapse uses NaCl (http://nacl.cr.yp.to/) for
  171. encryption and digital signatures.
  172. Unfortunately PyNACL currently has a few issues
  173. (https://github.com/pyca/pynacl/issues/53) and
  174. (https://github.com/pyca/pynacl/issues/79) that mean it may not install
  175. correctly, causing all tests to fail with errors about missing "sodium.h". To
  176. fix try re-installing from PyPI or directly from
  177. (https://github.com/pyca/pynacl)::
  178. $ # Install from PyPI
  179. $ pip install --user --upgrade --force pynacl
  180. $ # Install from github
  181. $ pip install --user https://github.com/pyca/pynacl/tarball/master
  182. ArchLinux
  183. ---------
  184. If running `$ synctl start` fails wit 'returned non-zero exit status 1', you will need to explicitly call Python2.7 - either running as::
  185. $ python2.7 -m synapse.app.homeserver --daemonize -c homeserver.yaml --pid-file homeserver.pid
  186. ...or by editing synctl with the correct python executable.
  187. Homeserver Development
  188. ======================
  189. To check out a homeserver for development, clone the git repo into a working
  190. directory of your choice::
  191. $ git clone https://github.com/matrix-org/synapse.git
  192. $ cd synapse
  193. The homeserver has a number of external dependencies, that are easiest
  194. to install using pip and a virtualenv::
  195. $ virtualenv env
  196. $ source env/bin/activate
  197. $ python synapse/python_dependencies.py | xargs -n1 pip install
  198. $ pip install setuptools_trial mock
  199. This will run a process of downloading and installing all the needed
  200. dependencies into a virtual env.
  201. Once this is done, you may wish to run the homeserver's unit tests, to
  202. check that everything is installed as it should be::
  203. $ python setup.py test
  204. This should end with a 'PASSED' result::
  205. Ran 143 tests in 0.601s
  206. PASSED (successes=143)
  207. Upgrading an existing homeserver
  208. ================================
  209. IMPORTANT: Before upgrading an existing homeserver to a new version, please
  210. refer to UPGRADE.rst for any additional instructions.
  211. Otherwise, simply re-install the new codebase over the current one - e.g.
  212. by ``pip install --process-dependency-links
  213. https://github.com/matrix-org/synapse/tarball/master``
  214. if using pip, or by ``git pull`` if running off a git working copy.
  215. Setting up Federation
  216. =====================
  217. In order for other homeservers to send messages to your server, it will need to
  218. be publicly visible on the internet, and they will need to know its host name.
  219. You have two choices here, which will influence the form of your Matrix user
  220. IDs:
  221. 1) Use the machine's own hostname as available on public DNS in the form of
  222. its A or AAAA records. This is easier to set up initially, perhaps for
  223. testing, but lacks the flexibility of SRV.
  224. 2) Set up a SRV record for your domain name. This requires you create a SRV
  225. record in DNS, but gives the flexibility to run the server on your own
  226. choice of TCP port, on a machine that might not be the same name as the
  227. domain name.
  228. For the first form, simply pass the required hostname (of the machine) as the
  229. --server-name parameter::
  230. $ python -m synapse.app.homeserver \
  231. --server-name machine.my.domain.name \
  232. --config-path homeserver.yaml \
  233. --generate-config
  234. $ python -m synapse.app.homeserver --config-path homeserver.yaml
  235. Alternatively, you can run ``synctl start`` to guide you through the process.
  236. For the second form, first create your SRV record and publish it in DNS. This
  237. needs to be named _matrix._tcp.YOURDOMAIN, and point at at least one hostname
  238. and port where the server is running. (At the current time synapse does not
  239. support clustering multiple servers into a single logical homeserver). The DNS
  240. record would then look something like::
  241. $ dig -t srv _matrix._tcp.machine.my.domaine.name
  242. _matrix._tcp IN SRV 10 0 8448 machine.my.domain.name.
  243. At this point, you should then run the homeserver with the hostname of this
  244. SRV record, as that is the name other machines will expect it to have::
  245. $ python -m synapse.app.homeserver \
  246. --server-name YOURDOMAIN \
  247. --bind-port 8448 \
  248. --config-path homeserver.yaml \
  249. --generate-config
  250. $ python -m synapse.app.homeserver --config-path homeserver.yaml
  251. You may additionally want to pass one or more "-v" options, in order to
  252. increase the verbosity of logging output; at least for initial testing.
  253. For the initial alpha release, the homeserver is not speaking TLS for
  254. either client-server or server-server traffic for ease of debugging. We have
  255. also not spent any time yet getting the homeserver to run behind loadbalancers.
  256. Running a Demo Federation of Homeservers
  257. ----------------------------------------
  258. If you want to get up and running quickly with a trio of homeservers in a
  259. private federation (``localhost:8080``, ``localhost:8081`` and
  260. ``localhost:8082``) which you can then access through the webclient running at
  261. http://localhost:8080. Simply run::
  262. $ demo/start.sh
  263. This is mainly useful just for development purposes.
  264. Running The Demo Web Client
  265. ===========================
  266. The homeserver runs a web client by default at https://localhost:8448/.
  267. If this is the first time you have used the client from that browser (it uses
  268. HTML5 local storage to remember its config), you will need to log in to your
  269. account. If you don't yet have an account, because you've just started the
  270. homeserver for the first time, then you'll need to register one.
  271. Registering A New Account
  272. -------------------------
  273. Your new user name will be formed partly from the hostname your server is
  274. running as, and partly from a localpart you specify when you create the
  275. account. Your name will take the form of::
  276. @localpart:my.domain.here
  277. (pronounced "at localpart on my dot domain dot here")
  278. Specify your desired localpart in the topmost box of the "Register for an
  279. account" form, and click the "Register" button. Hostnames can contain ports if
  280. required due to lack of SRV records (e.g. @matthew:localhost:8448 on an
  281. internal synapse sandbox running on localhost)
  282. Logging In To An Existing Account
  283. ---------------------------------
  284. Just enter the ``@localpart:my.domain.here`` Matrix user ID and password into
  285. the form and click the Login button.
  286. Identity Servers
  287. ================
  288. The job of authenticating 3PIDs and tracking which 3PIDs are associated with a
  289. given Matrix user is very security-sensitive, as there is obvious risk of spam
  290. if it is too easy to sign up for Matrix accounts or harvest 3PID data.
  291. Meanwhile the job of publishing the end-to-end encryption public keys for
  292. Matrix users is also very security-sensitive for similar reasons.
  293. Therefore the role of managing trusted identity in the Matrix ecosystem is
  294. farmed out to a cluster of known trusted ecosystem partners, who run 'Matrix
  295. Identity Servers' such as ``sydent``, whose role is purely to authenticate and
  296. track 3PID logins and publish end-user public keys.
  297. It's currently early days for identity servers as Matrix is not yet using 3PIDs
  298. as the primary means of identity and E2E encryption is not complete. As such,
  299. we are running a single identity server (http://matrix.org:8090) at the current
  300. time.
  301. Where's the spec?!
  302. ==================
  303. The source of the matrix spec lives at https://github.com/matrix-org/matrix-doc.
  304. A recent HTML snapshot of this lives at http://matrix.org/docs/spec
  305. Building Internal API Documentation
  306. ===================================
  307. Before building internal API documentation install sphinx and
  308. sphinxcontrib-napoleon::
  309. $ pip install sphinx
  310. $ pip install sphinxcontrib-napoleon
  311. Building internal API documentation::
  312. $ python setup.py build_sphinx