README.rst 16 KB

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