README.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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:8008``.
  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
  75. Installing prerequisites on Mac OS X::
  76. $ xcode-select --install
  77. To install the synapse homeserver run::
  78. $ pip install --user --process-dependency-links https://github.com/matrix-org/synapse/tarball/master
  79. This installs synapse, along with the libraries it uses, into
  80. ``$HOME/.local/lib/`` on Linux or ``$HOME/Library/Python/2.7/lib/`` on OSX.
  81. Your python may not give priority to locally installed libraries over system
  82. libraries, in which case you must add your local packages to your python path::
  83. $ # on Linux:
  84. $ export PYTHONPATH=$HOME/.local/lib/python2.7/site-packages:$PYTHONPATH
  85. $ # on OSX:
  86. $ export PYTHONPATH=$HOME/Library/Python/2.7/lib/python/site-packages:$PYTHONPATH
  87. For reliable VoIP calls to be routed via this homeserver, you MUST configure
  88. a TURN server. See docs/turn-howto.rst for details.
  89. Troubleshooting Installation
  90. ----------------------------
  91. Synapse requires pip 1.7 or later, so if your OS provides too old a version and
  92. you get errors about ``error: no such option: --process-dependency-links`` you
  93. may need to manually upgrade it::
  94. $ sudo pip install --upgrade pip
  95. If pip crashes mid-installation for reason (e.g. lost terminal), pip may
  96. refuse to run until you remove the temporary installation directory it
  97. created. To reset the installation::
  98. $ rm -rf /tmp/pip_install_matrix
  99. pip seems to leak *lots* of memory during installation. For instance, a Linux
  100. host with 512MB of RAM may run out of memory whilst installing Twisted. If this
  101. happens, you will have to individually install the dependencies which are
  102. failing, e.g.::
  103. $ pip install --user twisted
  104. On OSX, if you encounter clang: error: unknown argument: '-mno-fused-madd' you
  105. will need to export CFLAGS=-Qunused-arguments.
  106. Windows Install
  107. ---------------
  108. Synapse can be installed on Cygwin. It requires the following Cygwin packages:
  109. - gcc
  110. - git
  111. - libffi-devel
  112. - openssl (and openssl-devel, python-openssl)
  113. - python
  114. - python-setuptools
  115. The content repository requires additional packages and will be unable to process
  116. uploads without them:
  117. - libjpeg8
  118. - libjpeg8-devel
  119. - zlib
  120. If you choose to install Synapse without these packages, you will need to reinstall
  121. ``pillow`` for changes to be applied, e.g. ``pip uninstall pillow`` ``pip install
  122. pillow --user``
  123. Troubleshooting:
  124. - You may need to upgrade ``setuptools`` to get this to work correctly:
  125. ``pip install setuptools --upgrade``.
  126. - You may encounter errors indicating that ``ffi.h`` is missing, even with
  127. ``libffi-devel`` installed. If you do, copy the ``.h`` files:
  128. ``cp /usr/lib/libffi-3.0.13/include/*.h /usr/include``
  129. - You may need to install libsodium from source in order to install PyNacl. If
  130. you do, you may need to create a symlink to ``libsodium.a`` so ``ld`` can find
  131. it: ``ln -s /usr/local/lib/libsodium.a /usr/lib/libsodium.a``
  132. Running Your Homeserver
  133. =======================
  134. To actually run your new homeserver, pick a working directory for Synapse to run
  135. (e.g. ``~/.synapse``), and::
  136. $ mkdir ~/.synapse
  137. $ cd ~/.synapse
  138. $ # on Linux
  139. $ ~/.local/bin/synctl start
  140. $ # on OSX
  141. $ ~/Library/Python/2.7/bin/synctl start
  142. Troubleshooting Running
  143. -----------------------
  144. If ``synctl`` fails with ``pkg_resources.DistributionNotFound`` errors you may
  145. need a newer version of setuptools than that provided by your OS.::
  146. $ sudo pip install setuptools --upgrade
  147. If synapse fails with ``missing "sodium.h"`` crypto errors, you may need
  148. to manually upgrade PyNaCL, as synapse uses NaCl (http://nacl.cr.yp.to/) for
  149. encryption and digital signatures.
  150. Unfortunately PyNACL currently has a few issues
  151. (https://github.com/pyca/pynacl/issues/53) and
  152. (https://github.com/pyca/pynacl/issues/79) that mean it may not install
  153. correctly, causing all tests to fail with errors about missing "sodium.h". To
  154. fix try re-installing from PyPI or directly from
  155. (https://github.com/pyca/pynacl)::
  156. $ # Install from PyPI
  157. $ pip install --user --upgrade --force pynacl
  158. $ # Install from github
  159. $ pip install --user https://github.com/pyca/pynacl/tarball/master
  160. Homeserver Development
  161. ======================
  162. To check out a homeserver for development, clone the git repo into a working
  163. directory of your choice::
  164. $ git clone https://github.com/matrix-org/synapse.git
  165. $ cd synapse
  166. The homeserver has a number of external dependencies, that are easiest
  167. to install by making setup.py do so, in --user mode::
  168. $ python setup.py develop --user
  169. This will run a process of downloading and installing into your
  170. user's .local/lib directory all of the required dependencies that are
  171. missing.
  172. Once this is done, you may wish to run the homeserver's unit tests, to
  173. check that everything is installed as it should be::
  174. $ python setup.py test
  175. This should end with a 'PASSED' result::
  176. Ran 143 tests in 0.601s
  177. PASSED (successes=143)
  178. Upgrading an existing homeserver
  179. ================================
  180. IMPORTANT: Before upgrading an existing homeserver to a new version, please
  181. refer to UPGRADE.rst for any additional instructions.
  182. Otherwise, simply re-install the new codebase over the current one - e.g.
  183. by ``pip install --user --process-dependency-links
  184. https://github.com/matrix-org/synapse/tarball/master``
  185. if using pip, or by ``git pull`` if running off a git working copy.
  186. Setting up Federation
  187. =====================
  188. In order for other homeservers to send messages to your server, it will need to
  189. be publicly visible on the internet, and they will need to know its host name.
  190. You have two choices here, which will influence the form of your Matrix user
  191. IDs:
  192. 1) Use the machine's own hostname as available on public DNS in the form of
  193. its A or AAAA records. This is easier to set up initially, perhaps for
  194. testing, but lacks the flexibility of SRV.
  195. 2) Set up a SRV record for your domain name. This requires you create a SRV
  196. record in DNS, but gives the flexibility to run the server on your own
  197. choice of TCP port, on a machine that might not be the same name as the
  198. domain name.
  199. For the first form, simply pass the required hostname (of the machine) as the
  200. --server-name parameter::
  201. $ python -m synapse.app.homeserver \
  202. --server-name machine.my.domain.name \
  203. --config-path homeserver.config \
  204. --generate-config
  205. $ python -m synapse.app.homeserver --config-path homeserver.config
  206. Alternatively, you can run ``synctl start`` to guide you through the process.
  207. For the second form, first create your SRV record and publish it in DNS. This
  208. needs to be named _matrix._tcp.YOURDOMAIN, and point at at least one hostname
  209. and port where the server is running. (At the current time synapse does not
  210. support clustering multiple servers into a single logical homeserver). The DNS
  211. record would then look something like::
  212. $ dig -t srv _matrix._tcp.machine.my.domaine.name
  213. _matrix._tcp IN SRV 10 0 8448 machine.my.domain.name.
  214. At this point, you should then run the homeserver with the hostname of this
  215. SRV record, as that is the name other machines will expect it to have::
  216. $ python -m synapse.app.homeserver \
  217. --server-name YOURDOMAIN \
  218. --bind-port 8448 \
  219. --config-path homeserver.config \
  220. --generate-config
  221. $ python -m synapse.app.homeserver --config-path homeserver.config
  222. You may additionally want to pass one or more "-v" options, in order to
  223. increase the verbosity of logging output; at least for initial testing.
  224. For the initial alpha release, the homeserver is not speaking TLS for
  225. either client-server or server-server traffic for ease of debugging. We have
  226. also not spent any time yet getting the homeserver to run behind loadbalancers.
  227. Running a Demo Federation of Homeservers
  228. ----------------------------------------
  229. If you want to get up and running quickly with a trio of homeservers in a
  230. private federation (``localhost:8080``, ``localhost:8081`` and
  231. ``localhost:8082``) which you can then access through the webclient running at
  232. http://localhost:8080. Simply run::
  233. $ demo/start.sh
  234. This is mainly useful just for development purposes.
  235. Running The Demo Web Client
  236. ===========================
  237. The homeserver runs a web client by default at https://localhost:8448/.
  238. If this is the first time you have used the client from that browser (it uses
  239. HTML5 local storage to remember its config), you will need to log in to your
  240. account. If you don't yet have an account, because you've just started the
  241. homeserver for the first time, then you'll need to register one.
  242. Registering A New Account
  243. -------------------------
  244. Your new user name will be formed partly from the hostname your server is
  245. running as, and partly from a localpart you specify when you create the
  246. account. Your name will take the form of::
  247. @localpart:my.domain.here
  248. (pronounced "at localpart on my dot domain dot here")
  249. Specify your desired localpart in the topmost box of the "Register for an
  250. account" form, and click the "Register" button. Hostnames can contain ports if
  251. required due to lack of SRV records (e.g. @matthew:localhost:8448 on an
  252. internal synapse sandbox running on localhost)
  253. Logging In To An Existing Account
  254. ---------------------------------
  255. Just enter the ``@localpart:my.domain.here`` Matrix user ID and password into
  256. the form and click the Login button.
  257. Identity Servers
  258. ================
  259. The job of authenticating 3PIDs and tracking which 3PIDs are associated with a
  260. given Matrix user is very security-sensitive, as there is obvious risk of spam
  261. if it is too easy to sign up for Matrix accounts or harvest 3PID data.
  262. Meanwhile the job of publishing the end-to-end encryption public keys for
  263. Matrix users is also very security-sensitive for similar reasons.
  264. Therefore the role of managing trusted identity in the Matrix ecosystem is
  265. farmed out to a cluster of known trusted ecosystem partners, who run 'Matrix
  266. Identity Servers' such as ``sydent``, whose role is purely to authenticate and
  267. track 3PID logins and publish end-user public keys.
  268. It's currently early days for identity servers as Matrix is not yet using 3PIDs
  269. as the primary means of identity and E2E encryption is not complete. As such,
  270. we are running a single identity server (http://matrix.org:8090) at the current
  271. time.
  272. Where's the spec?!
  273. ==================
  274. The source of the matrix spec lives at https://github.com/matrix-org/matrix-doc.
  275. A recent HTML snapshot of this lives at http://matrix.org/docs/spec
  276. Building Internal API Documentation
  277. ===================================
  278. Before building internal API documentation install sphinx and
  279. sphinxcontrib-napoleon::
  280. $ pip install sphinx
  281. $ pip install sphinxcontrib-napoleon
  282. Building internal API documentation::
  283. $ python setup.py build_sphinx