From 514df1f6480019dd6d4070a981b04c56a7920b05 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Aug 2014 02:33:04 +0100 Subject: [PATCH 01/17] actually register the login servlet (uncommitted code thinko?) --- synapse/rest/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 559829579..3d4dd098d 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -14,7 +14,7 @@ # limitations under the License. from . import ( - room, events, register, profile, public, presence, im, directory + room, events, register, login, profile, public, presence, im, directory ) class RestServletFactory(object): @@ -35,10 +35,9 @@ class RestServletFactory(object): room.register_servlets(hs, http_server) events.register_servlets(hs, http_server) register.register_servlets(hs, http_server) + login.register_servlets(hs, http_server) profile.register_servlets(hs, http_server) public.register_servlets(hs, http_server) presence.register_servlets(hs, http_server) im.register_servlets(hs, http_server) directory.register_servlets(hs, http_server) - - From d314315a2e8c87eeb99b8d484e11e9dc2e3e1cb3 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Aug 2014 03:01:27 +0100 Subject: [PATCH 02/17] remove remaining TODOs and fill in lots more info --- README.rst | 133 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 106 insertions(+), 27 deletions(-) diff --git a/README.rst b/README.rst index c58ebf0db..ce0d51036 100644 --- a/README.rst +++ b/README.rst @@ -1,16 +1,18 @@ About ===== -Matrix is an ambitious new ecosystem for open federated Instant Messaging and VoIP[1]. +Matrix is an ambitious new ecosystem for open federated Instant Messaging and +VoIP[1]. -Matrix specifies a set of pragmatic RESTful HTTP JSON APIs as an open standard, providing: +Matrix specifies a set of pragmatic RESTful HTTP JSON APIs as an open standard, +providing: - Creating and managing fully distributed chat rooms with no single points of control or failure - - Eventually-consistent cryptographically secure synchronisation of room + - Eventually-consistent cryptographically secure[2] synchronisation of room state across a global open network of federated servers and services - Sending and receiving extensible messages in a room with (optional) - end-to-end encryption[2] + end-to-end encryption[3] - Inviting, joining, leaving, kicking, banning room members - Managing user accounts (registration, login, logout) - Using 3rd Party IDs (3PIDs) such as email addresses, phone numbers, @@ -18,11 +20,11 @@ Matrix specifies a set of pragmatic RESTful HTTP JSON APIs as an open standard, - Placing 1:1 VoIP and Video calls (in development) These APIs are intended to be implemented on a wide range of servers, services -and clients which then form the Matrix ecosystem, and allow developers to build -messaging and VoIP functionality on top of the open Matrix community rather than -using closed or proprietary solutions. The hope is for Matrix to act as the -building blocks for a new generation of fully open and interoperable messaging -and VoIP apps for the internet. +and clients, letting developers build messaging and VoIP functionality on top of +the entirely open Matrix ecosystem rather than using closed or proprietary +solutions. The hope is for Matrix to act as the building blocks for a new +generation of fully open and interoperable messaging and VoIP apps for the +internet. Synapse is a reference "homeserver" implementation of Matrix from the core development team at matrix.org, written in Python/Twisted for clarity and @@ -38,16 +40,56 @@ control and own your own communications and history or use one hosted by someone else (e.g. matrix.org) - there is no single point of control or mandatory service provider in Matrix, unlike WhatsApp, Facebook, Hangouts, etc. -Synapse ships with two basic demo Matrix clients: webclient (a basic group chat web client demo implemented in AngularJS) and cmdclient (a basic Python commandline utility which lets you easily see what the JSON APIs are up to). +Synapse ships with two basic demo Matrix clients: webclient (a basic group chat +web client demo implemented in AngularJS) and cmdclient (a basic Python +commandline utility which lets you easily see what the JSON APIs are up to). -We'd like to invite you to take a look at the Matrix spec, try to run a homeserver, and join the existing Matrix chatrooms already out there, experiment with the APIs and the demo clients, and let us know your thoughts at https://github.com/matrix-org/synapse/issues or at matrix@matrix.org. +We'd like to invite you to take a look at the Matrix spec, try to run a +homeserver, and join the existing Matrix chatrooms already out there, experiment +with the APIs and the demo clients, and let us know your thoughts at +https://github.com/matrix-org/synapse/issues or at matrix@matrix.org. Thanks for trying Matrix! -[1] VoIP currently in development +.. [1] VoIP currently in development +.. [2] Cryptographic signing of messages isn't turned on yet +.. [3] End-to-end encryption is currently in development -[2] End-to-end encryption is currently in development +Quick Start +=========== +The basics you need to know about Matrix are: + + - Chatrooms look like ``#matrix:matrix.org`` or ``#test:localhost:8080`` + + - Matrix user IDs look like ``@matthew:matrix.org`` (although in the future + you will normally refer to yourself and others using a 3PID: email + address, phone number, etc rather than manipulating matrix user IDs) + + - To simply play with an **existing** homeserver (e.g. matrix.org), you can + just go straight to http://matrix.org/alpha, specify a homeserver + (defaults to matrix.org) and sign up and use it. (Sign-up security is + currently work-in-progress) + + - To run your own **private** homeserver on localhost:8080, install synapse + with ``python setup.py develop --user`` and then run one with + ``python synapse/app/homeserver.py`` + + - To run your own webclient: + ``cd webclient; python -m SimpleHTTPServer`` and hit http://localhost:8000 + in your web browser (a recent Chrome, Safari or Firefox for now, + please...) + + - For now, register some accounts like ``@testing:localhost:8080`` from + different browsers, join a room like ``#test:localhost:8080`` and have a + play. + + - To quickly run a **public** homeserver that can exchange messages with + other homeservers and participate in the overall Matrix federation, open + up port 8080 and run ``python synapse/app/homeserver.py --host + machine.my.domain.name``. Then come join ``#matrix:matrix.org`` and + say hi! :) + Directory Structure =================== @@ -58,10 +100,10 @@ Directory Structure ├── cmdclient Basic CLI python Matrix client ├── demo Scripts for running standalone Matrix demos ├── docs All doc, including the draft Matrix API spec - │   ├── client-server The client-server Matrix API spec - │   ├── model Domain-specific elements of the Matrix API spec - │   ├── server-server The server-server model of the Matrix API spec - │   └── sphinx The internal API doc of the Synapse homeserver + │   ├── client-server The client-server Matrix API spec + │   ├── model Domain-specific elements of the Matrix API spec + │   ├── server-server The server-server model of the Matrix API spec + │   └── sphinx The internal API doc of the Synapse homeserver ├── experiments Early experiments of using Synapse's internal APIs ├── graph Visualisation of Matrix's distributed message store ├── synapse The reference Matrix homeserver implementation @@ -82,13 +124,12 @@ Directory Structure └── webclient Basic AngularJS Matrix web client -Installation -============ +Homeserver Installation +======================= First, the dependencies need to be installed. Start by installing 'python2.7-dev' and the various tools of the compiler toolchain. - -N.B. that python 2.x where x >= 7 is required. +N.B. synapse requires python 2.x where x >= 7 Installing prerequisites on ubuntu:: @@ -102,6 +143,12 @@ The homeserver has a number of external dependencies, that are easiest to install by making setup.py do so, in --user mode:: $ python setup.py develop --user + +You'll need a version of setuptools new enough to know about git, so you +may need to also run: + + $ sudo apt-get install python-pip + $ sudo pip install --upgrade setuptools This will run a process of downloading and installing into your user's .local/lib directory all of the required dependencies that are @@ -161,6 +208,14 @@ For the initial alpha release, the homeserver is not speaking TLS for either client-server or server-server traffic for ease of debugging. We have also not spent any time yet getting the homeserver to run behind loadbalancers. +Running a Demo Federation of Homeservers +---------------------------------------- + +If you want to get up and running quickly with a trio of homeservers in a +private federation (``localhost:8080``, ``localhost:8081`` and +``localhost:8082``) which you can then point a demo webclient at, simply run:: + + $ demo/start.sh Running The Demo Web Client =========================== @@ -200,19 +255,43 @@ synapse sandbox running on localhost) Logging In To An Existing Account --------------------------------- -[[TODO(paul): It seems the current web client still requests an access_token - - I suspect this part will need updating before we can point people at how to - perform e.g. user+password or 3PID authenticated login]] +Just enter the ``@localpart:my.domain.here`` matrix user ID and password into the form and click the Login button. -Building Documentation +Identity Servers +================ + +The job of authenticating 3PIDs and tracking which 3PIDs are associated with a +given matrix user is very security-sensitive, as there is obvious risk of spam +if it is too easy to sign up for Matrix accounts or harvest 3PID data. Meanwhile +the job of publishing the end-to-end encryption public keys for Matrix users is +also very security-sensitive for similar reasons. + +Therefore the role of managing trusted identity in the Matrix ecosystem is +farmed out to a cluster of known trusted ecosystem partners, who run 'Matrix +Identity Servers' such as ``sydent``, whose role is purely to authenticate and +track 3PID logins and publish end-user public keys. + +It's currently early days for identity servers as Matrix is not yet using 3PIDs +as the primary means of identity and E2E encryption is not complete. As such, +we're not yet running an identity server in public. + + +How does it all work?! ====================== -Before building documentation install spinx and sphinxcontrib-napoleon:: +For now, please go spelunking in the ``docs/`` directory to find out. + + +Building Internal API Documentation +=================================== + +Before building internal API documentation install spinx and +sphinxcontrib-napoleon:: $ pip install sphinx $ pip install sphinxcontrib-napoleon -Building documentation:: +Building internal API documentation:: $ python setup.py build_sphinx From f98e6380f15c68a052e7ccb03b123b6eb91474ea Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Aug 2014 03:14:34 +0100 Subject: [PATCH 03/17] add in whitespace after copyright statements to improve legibility --- synapse/__init__.py | 1 + synapse/api/__init__.py | 1 + synapse/api/auth.py | 1 + synapse/api/constants.py | 1 + synapse/api/errors.py | 1 + synapse/api/events/__init__.py | 1 + synapse/api/events/factory.py | 1 + synapse/api/events/room.py | 1 + synapse/api/notifier.py | 1 + synapse/api/streams/__init__.py | 1 + synapse/api/streams/event.py | 1 + synapse/app/__init__.py | 1 + synapse/app/homeserver.py | 2 +- synapse/crypto/__init__.py | 1 + synapse/crypto/config.py | 1 + synapse/crypto/keyclient.py | 1 + synapse/crypto/keyserver.py | 1 + synapse/crypto/resource/__init__.py | 1 + synapse/crypto/resource/key.py | 1 + synapse/federation/__init__.py | 1 + synapse/federation/handler.py | 1 + synapse/federation/pdu_codec.py | 1 + synapse/federation/persistence.py | 1 + synapse/federation/replication.py | 1 + synapse/federation/transport.py | 1 + synapse/federation/units.py | 1 + synapse/handlers/__init__.py | 1 + synapse/handlers/_base.py | 1 + synapse/handlers/directory.py | 1 + synapse/handlers/events.py | 1 + synapse/handlers/federation.py | 1 + synapse/handlers/login.py | 1 + synapse/handlers/presence.py | 1 + synapse/handlers/profile.py | 1 + synapse/handlers/register.py | 1 + synapse/handlers/room.py | 1 + synapse/http/__init__.py | 1 + synapse/http/client.py | 1 + synapse/http/endpoint.py | 1 + synapse/http/server.py | 1 + synapse/rest/__init__.py | 1 + synapse/rest/base.py | 1 + synapse/rest/directory.py | 1 + synapse/rest/events.py | 1 + synapse/rest/im.py | 1 + synapse/rest/login.py | 1 + synapse/rest/presence.py | 1 + synapse/rest/profile.py | 1 + synapse/rest/public.py | 1 + synapse/rest/register.py | 1 + synapse/rest/room.py | 1 + synapse/server.py | 1 + synapse/state.py | 1 + synapse/storage/__init__.py | 1 + synapse/storage/_base.py | 1 + synapse/storage/directory.py | 1 + synapse/storage/feedback.py | 1 + synapse/storage/message.py | 1 + synapse/storage/pdu.py | 1 + synapse/storage/presence.py | 1 + synapse/storage/profile.py | 1 + synapse/storage/registration.py | 1 + synapse/storage/room.py | 1 + synapse/storage/roomdata.py | 1 + synapse/storage/roommember.py | 1 + synapse/storage/stream.py | 1 + synapse/storage/transactions.py | 1 + synapse/types.py | 1 + synapse/util/__init__.py | 1 + synapse/util/async.py | 1 + synapse/util/distributor.py | 1 + synapse/util/jsonobject.py | 1 + synapse/util/lockutils.py | 1 + synapse/util/logutils.py | 1 + synapse/util/stringutils.py | 1 + tests/test_distributor.py | 1 + 76 files changed, 76 insertions(+), 1 deletion(-) diff --git a/synapse/__init__.py b/synapse/__init__.py index aa760fb34..1e7b2ab27 100644 --- a/synapse/__init__.py +++ b/synapse/__init__.py @@ -12,5 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This is a reference implementation of a synapse home server. """ diff --git a/synapse/api/__init__.py b/synapse/api/__init__.py index fe8a073cd..2216c0f1c 100644 --- a/synapse/api/__init__.py +++ b/synapse/api/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/api/auth.py b/synapse/api/auth.py index 5c66a7261..84bc0398f 100644 --- a/synapse/api/auth.py +++ b/synapse/api/auth.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains classes for authenticating the user.""" from twisted.internet import defer diff --git a/synapse/api/constants.py b/synapse/api/constants.py index 37bf41bfb..29687c348 100644 --- a/synapse/api/constants.py +++ b/synapse/api/constants.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains constants from the specification.""" diff --git a/synapse/api/errors.py b/synapse/api/errors.py index 7ad4d636c..8b9766fab 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains exceptions and error codes.""" import logging diff --git a/synapse/api/events/__init__.py b/synapse/api/events/__init__.py index bc2daf336..921fd0883 100644 --- a/synapse/api/events/__init__.py +++ b/synapse/api/events/__init__.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.errors import SynapseError, Codes from synapse.util.jsonobject import JsonEncodedObject diff --git a/synapse/api/events/factory.py b/synapse/api/events/factory.py index ea7afa234..12aa04fc6 100644 --- a/synapse/api/events/factory.py +++ b/synapse/api/events/factory.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.events.room import ( RoomTopicEvent, MessageEvent, RoomMemberEvent, FeedbackEvent, InviteJoinEvent, RoomConfigEvent diff --git a/synapse/api/events/room.py b/synapse/api/events/room.py index b31cd19f4..f3df849af 100644 --- a/synapse/api/events/room.py +++ b/synapse/api/events/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from . import SynapseEvent diff --git a/synapse/api/notifier.py b/synapse/api/notifier.py index 974f7f0ba..22d2914d3 100644 --- a/synapse/api/notifier.py +++ b/synapse/api/notifier.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.constants import Membership from synapse.api.events.room import RoomMemberEvent diff --git a/synapse/api/streams/__init__.py b/synapse/api/streams/__init__.py index 08137c1e7..989e63f9e 100644 --- a/synapse/api/streams/__init__.py +++ b/synapse/api/streams/__init__.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.errors import SynapseError diff --git a/synapse/api/streams/event.py b/synapse/api/streams/event.py index 0cc1a3e36..4b6d739e5 100644 --- a/synapse/api/streams/event.py +++ b/synapse/api/streams/event.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains classes for streaming from the event stream: /events. """ from twisted.internet import defer diff --git a/synapse/app/__init__.py b/synapse/app/__init__.py index fe8a073cd..2216c0f1c 100644 --- a/synapse/app/__init__.py +++ b/synapse/app/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 5708b3ad9..9ad8ac7f0 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright 2014 matrix.org # @@ -12,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -#!/usr/bin/env python from synapse.storage import read_schema diff --git a/synapse/crypto/__init__.py b/synapse/crypto/__init__.py index fe8a073cd..2216c0f1c 100644 --- a/synapse/crypto/__init__.py +++ b/synapse/crypto/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/crypto/config.py b/synapse/crypto/config.py index 801dfd865..2330133e7 100644 --- a/synapse/crypto/config.py +++ b/synapse/crypto/config.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + import ConfigParser as configparser import argparse import socket diff --git a/synapse/crypto/keyclient.py b/synapse/crypto/keyclient.py index b53d1c572..e615866b6 100644 --- a/synapse/crypto/keyclient.py +++ b/synapse/crypto/keyclient.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.web.http import HTTPClient from twisted.internet import defer, reactor from twisted.internet.protocol import ClientFactory diff --git a/synapse/crypto/keyserver.py b/synapse/crypto/keyserver.py index 48bd38078..3d80a0e66 100644 --- a/synapse/crypto/keyserver.py +++ b/synapse/crypto/keyserver.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import reactor, ssl from twisted.web import server from twisted.web.resource import Resource diff --git a/synapse/crypto/resource/__init__.py b/synapse/crypto/resource/__init__.py index fe8a073cd..2216c0f1c 100644 --- a/synapse/crypto/resource/__init__.py +++ b/synapse/crypto/resource/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/crypto/resource/key.py b/synapse/crypto/resource/key.py index 6ce6e0b03..6aecd2b95 100644 --- a/synapse/crypto/resource/key.py +++ b/synapse/crypto/resource/key.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.web.resource import Resource from twisted.web.server import NOT_DONE_YET from twisted.internet import defer diff --git a/synapse/federation/__init__.py b/synapse/federation/__init__.py index b4d95ed5a..ac0c10dc3 100644 --- a/synapse/federation/__init__.py +++ b/synapse/federation/__init__.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This package includes all the federation specific logic. """ diff --git a/synapse/federation/handler.py b/synapse/federation/handler.py index 31e8470b3..d361f0aaf 100644 --- a/synapse/federation/handler.py +++ b/synapse/federation/handler.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from .pdu_codec import PduCodec diff --git a/synapse/federation/pdu_codec.py b/synapse/federation/pdu_codec.py index 9155930e4..adc166c56 100644 --- a/synapse/federation/pdu_codec.py +++ b/synapse/federation/pdu_codec.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from .units import Pdu import copy diff --git a/synapse/federation/persistence.py b/synapse/federation/persistence.py index ad4111c68..372245712 100644 --- a/synapse/federation/persistence.py +++ b/synapse/federation/persistence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains all the persistence actions done by the federation package. diff --git a/synapse/federation/replication.py b/synapse/federation/replication.py index 0f5b97429..bea5335f8 100644 --- a/synapse/federation/replication.py +++ b/synapse/federation/replication.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This layer is responsible for replicating with remote home servers using a given transport. """ diff --git a/synapse/federation/transport.py b/synapse/federation/transport.py index 2136adf8d..09a5e5901 100644 --- a/synapse/federation/transport.py +++ b/synapse/federation/transport.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """The transport layer is responsible for both sending transactions to remote home servers and receiving a variety of requests from other home servers. diff --git a/synapse/federation/units.py b/synapse/federation/units.py index 0efea7b76..2b2f11f36 100644 --- a/synapse/federation/units.py +++ b/synapse/federation/units.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ Defines the JSON structure of the protocol units used by the server to server protocol. """ diff --git a/synapse/handlers/__init__.py b/synapse/handlers/__init__.py index 5688b68e4..8a4aa6e5d 100644 --- a/synapse/handlers/__init__.py +++ b/synapse/handlers/__init__.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from .register import RegistrationHandler from .room import ( MessageHandler, RoomCreationHandler, RoomMemberHandler, RoomListHandler diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py index 87a392dd7..c2f4685c9 100644 --- a/synapse/handlers/_base.py +++ b/synapse/handlers/_base.py @@ -14,6 +14,7 @@ # limitations under the License. + class BaseHandler(object): def __init__(self, hs): diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py index 456007c71..3cc634890 100644 --- a/synapse/handlers/directory.py +++ b/synapse/handlers/directory.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from ._base import BaseHandler diff --git a/synapse/handlers/events.py b/synapse/handlers/events.py index 79742a4e1..3af7d824a 100644 --- a/synapse/handlers/events.py +++ b/synapse/handlers/events.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from ._base import BaseHandler diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 12e7afca4..7026df90a 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains handlers for federation events.""" from ._base import BaseHandler diff --git a/synapse/handlers/login.py b/synapse/handlers/login.py index 5a1acd710..ca69829d7 100644 --- a/synapse/handlers/login.py +++ b/synapse/handlers/login.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from ._base import BaseHandler diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py index 38db4b1d6..1c24efd45 100644 --- a/synapse/handlers/presence.py +++ b/synapse/handlers/presence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.api.errors import SynapseError, AuthError diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index a27206b00..976b8cfcd 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.api.errors import SynapseError, AuthError diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 246c1f653..593c60334 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains functions for registering clients.""" from twisted.internet import defer diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 4d82b3399..eae40765b 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """Contains functions for performing events on rooms.""" from twisted.internet import defer diff --git a/synapse/http/__init__.py b/synapse/http/__init__.py index fe8a073cd..2216c0f1c 100644 --- a/synapse/http/__init__.py +++ b/synapse/http/__init__.py @@ -12,3 +12,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + diff --git a/synapse/http/client.py b/synapse/http/client.py index bb22b0ee9..d0facbdc6 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer, reactor from twisted.web.client import _AgentBase, _URI, readBody from twisted.web.http_headers import Headers diff --git a/synapse/http/endpoint.py b/synapse/http/endpoint.py index c4e6e63a8..d91500b07 100644 --- a/synapse/http/endpoint.py +++ b/synapse/http/endpoint.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet.endpoints import SSL4ClientEndpoint, TCP4ClientEndpoint from twisted.internet import defer from twisted.internet.error import ConnectError diff --git a/synapse/http/server.py b/synapse/http/server.py index 9fb45971d..d7f4b691b 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from syutil.jsonutil import ( encode_canonical_json, encode_pretty_printed_json ) diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index 3d4dd098d..b7f0c1fd2 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from . import ( room, events, register, login, profile, public, presence, im, directory ) diff --git a/synapse/rest/base.py b/synapse/rest/base.py index d90ac611f..2f1ab57c7 100644 --- a/synapse/rest/base.py +++ b/synapse/rest/base.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains base REST classes for constructing REST servlets. """ import re diff --git a/synapse/rest/directory.py b/synapse/rest/directory.py index a426003a3..31fd26e84 100644 --- a/synapse/rest/directory.py +++ b/synapse/rest/directory.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.types import RoomAlias, RoomID diff --git a/synapse/rest/events.py b/synapse/rest/events.py index 147257a94..dc811b813 100644 --- a/synapse/rest/events.py +++ b/synapse/rest/events.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains REST servlets to do with event streaming, /events.""" from twisted.internet import defer diff --git a/synapse/rest/im.py b/synapse/rest/im.py index 39f2dbd74..63a77716a 100644 --- a/synapse/rest/im.py +++ b/synapse/rest/im.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.api.streams import PaginationConfig diff --git a/synapse/rest/login.py b/synapse/rest/login.py index 0284e125b..88a321833 100644 --- a/synapse/rest/login.py +++ b/synapse/rest/login.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.api.errors import SynapseError diff --git a/synapse/rest/presence.py b/synapse/rest/presence.py index e4925c20a..604384859 100644 --- a/synapse/rest/presence.py +++ b/synapse/rest/presence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains REST servlets to do with presence: /presence/ """ from twisted.internet import defer diff --git a/synapse/rest/profile.py b/synapse/rest/profile.py index f384227c2..3d0427bf7 100644 --- a/synapse/rest/profile.py +++ b/synapse/rest/profile.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains REST servlets to do with profile: /profile/ """ from twisted.internet import defer diff --git a/synapse/rest/public.py b/synapse/rest/public.py index 6fd1731a6..3430c8049 100644 --- a/synapse/rest/public.py +++ b/synapse/rest/public.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains REST servlets to do with public paths: /public""" from twisted.internet import defer diff --git a/synapse/rest/register.py b/synapse/rest/register.py index f1cbce5c6..eb457562b 100644 --- a/synapse/rest/register.py +++ b/synapse/rest/register.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """This module contains REST servlets to do with registration: /register""" from twisted.internet import defer diff --git a/synapse/rest/room.py b/synapse/rest/room.py index c96de5e65..228bc9623 100644 --- a/synapse/rest/room.py +++ b/synapse/rest/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + """ This module contains REST servlets to do with rooms: /rooms/ """ from twisted.internet import defer diff --git a/synapse/server.py b/synapse/server.py index 0aff75f39..4ba203ac3 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + # This file provides some classes for setting up (partially-populated) # homeservers; either as a full homeserver as a real application, or a small # partial one for unit test mocking. diff --git a/synapse/state.py b/synapse/state.py index 439c0b519..b081de8f4 100644 --- a/synapse/state.py +++ b/synapse/state.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.federation.pdu_codec import encode_event_id diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py index ec93f9f8a..3c27428c0 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.events.room import ( RoomMemberEvent, MessageEvent, RoomTopicEvent, FeedbackEvent, RoomConfigEvent diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 4d98a6fd0..65f691ead 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import logging from twisted.internet import defer diff --git a/synapse/storage/directory.py b/synapse/storage/directory.py index 71fa9d9c9..b22ce02f3 100644 --- a/synapse/storage/directory.py +++ b/synapse/storage/directory.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore from twisted.internet import defer diff --git a/synapse/storage/feedback.py b/synapse/storage/feedback.py index 2b421e334..9bd562c76 100644 --- a/synapse/storage/feedback.py +++ b/synapse/storage/feedback.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from synapse.api.events.room import FeedbackEvent diff --git a/synapse/storage/message.py b/synapse/storage/message.py index 4822fa709..7bb69c138 100644 --- a/synapse/storage/message.py +++ b/synapse/storage/message.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from synapse.api.events.room import MessageEvent diff --git a/synapse/storage/pdu.py b/synapse/storage/pdu.py index a1cdde0a3..202d7f6cb 100644 --- a/synapse/storage/pdu.py +++ b/synapse/storage/pdu.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table, JoinHelper from synapse.util.logutils import log_function diff --git a/synapse/storage/presence.py b/synapse/storage/presence.py index e57ddaf14..6f5b042c2 100644 --- a/synapse/storage/presence.py +++ b/synapse/storage/presence.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore diff --git a/synapse/storage/profile.py b/synapse/storage/profile.py index d2f24930c..91dd56503 100644 --- a/synapse/storage/profile.py +++ b/synapse/storage/profile.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore diff --git a/synapse/storage/registration.py b/synapse/storage/registration.py index 4a970dd54..68cdfbb4c 100644 --- a/synapse/storage/registration.py +++ b/synapse/storage/registration.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from sqlite3 import IntegrityError diff --git a/synapse/storage/room.py b/synapse/storage/room.py index 174cbcf3d..09d9c2339 100644 --- a/synapse/storage/room.py +++ b/synapse/storage/room.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from sqlite3 import IntegrityError diff --git a/synapse/storage/roomdata.py b/synapse/storage/roomdata.py index 781d47793..cc04d1ba1 100644 --- a/synapse/storage/roomdata.py +++ b/synapse/storage/roomdata.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table import collections diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index e6e761779..ef73be4af 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer from synapse.types import UserID diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index c3b1bfeb3..1dedffac4 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore from .message import MessagesTable from .feedback import FeedbackTable diff --git a/synapse/storage/transactions.py b/synapse/storage/transactions.py index aa41e2ad7..a277e4971 100644 --- a/synapse/storage/transactions.py +++ b/synapse/storage/transactions.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from ._base import SQLBaseStore, Table from .pdu import PdusTable diff --git a/synapse/types.py b/synapse/types.py index 1adc95bbb..054b1e713 100644 --- a/synapse/types.py +++ b/synapse/types.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from synapse.api.errors import SynapseError from collections import namedtuple diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py index 5361cb7ec..3ea431a7f 100644 --- a/synapse/util/__init__.py +++ b/synapse/util/__init__.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import reactor import time diff --git a/synapse/util/async.py b/synapse/util/async.py index e04db8e28..ebbdc00ae 100644 --- a/synapse/util/async.py +++ b/synapse/util/async.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer, reactor diff --git a/synapse/util/distributor.py b/synapse/util/distributor.py index 32d19402b..9605d7d1b 100644 --- a/synapse/util/distributor.py +++ b/synapse/util/distributor.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer import logging diff --git a/synapse/util/jsonobject.py b/synapse/util/jsonobject.py index 190a80a32..e2840b59f 100644 --- a/synapse/util/jsonobject.py +++ b/synapse/util/jsonobject.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + import copy class JsonEncodedObject(object): diff --git a/synapse/util/lockutils.py b/synapse/util/lockutils.py index e4d609d84..758be0b90 100644 --- a/synapse/util/lockutils.py +++ b/synapse/util/lockutils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from twisted.internet import defer import logging diff --git a/synapse/util/logutils.py b/synapse/util/logutils.py index 08d5aafca..9270a1790 100644 --- a/synapse/util/logutils.py +++ b/synapse/util/logutils.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + from inspect import getcallargs import logging diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py index 91550583a..e1b0796e5 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import random import string diff --git a/tests/test_distributor.py b/tests/test_distributor.py index 36cbf6c52..db23f1667 100644 --- a/tests/test_distributor.py +++ b/tests/test_distributor.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import unittest from twisted.internet import defer From 3e35a9f96eae1720afbbd754f9e96e62070197d0 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Aug 2014 03:32:18 +0100 Subject: [PATCH 04/17] add in copyrights to everything, not just the synapse subdir, and add a copyrighter.pl whilst we're at it --- cmdclient/console.py | 17 +++++++++- cmdclient/http.py | 14 ++++++++ experiments/cursesio.py | 14 ++++++++ experiments/test_messaging.py | 14 ++++++++ graph/graph.py | 14 ++++++++ scripts/copyrighter.pl | 33 +++++++++++++++++++ setup.py | 14 ++++++++ tests/__init__.py | 14 ++++++++ tests/events/__init__.py | 14 ++++++++ tests/events/test_events.py | 14 ++++++++ tests/federation/test_federation.py | 14 ++++++++ tests/federation/test_pdu_codec.py | 14 ++++++++ tests/handlers/test_federation.py | 14 ++++++++ tests/handlers/test_presence.py | 14 ++++++++ tests/handlers/test_presencelike.py | 14 ++++++++ tests/handlers/test_profile.py | 14 ++++++++ tests/handlers/test_room.py | 14 ++++++++ tests/rest/__init__.py | 14 ++++++++ tests/rest/test_events.py | 14 ++++++++ tests/rest/test_presence.py | 14 ++++++++ tests/rest/test_profile.py | 14 ++++++++ tests/rest/test_rooms.py | 14 ++++++++ tests/rest/utils.py | 14 ++++++++ tests/storage/test_base.py | 14 ++++++++ tests/test_distributor.py | 14 ++++++++ tests/test_state.py | 14 ++++++++ tests/test_types.py | 15 +++++++++ tests/util/__init__.py | 14 ++++++++ tests/util/test_lock.py | 14 ++++++++ tests/utils.py | 15 +++++++++ webclient/app-controller.js | 16 +++++++++ webclient/app.js | 16 +++++++++ webclient/components/matrix/matrix-service.js | 16 +++++++++ webclient/room/room-controller.js | 16 +++++++++ webclient/rooms/rooms-controller.js | 16 +++++++++ 35 files changed, 523 insertions(+), 1 deletion(-) create mode 100755 scripts/copyrighter.pl diff --git a/cmdclient/console.py b/cmdclient/console.py index 595ce429c..6c6e2085b 100755 --- a/cmdclient/console.py +++ b/cmdclient/console.py @@ -1,4 +1,19 @@ -#! /usr/bin/env python +#!/usr/bin/env python + +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """ Starts a synapse client console. """ from twisted.internet import reactor, defer, threads diff --git a/cmdclient/http.py b/cmdclient/http.py index e71593837..9de6be9b7 100644 --- a/cmdclient/http.py +++ b/cmdclient/http.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from twisted.web.client import Agent, readBody from twisted.web.http_headers import Headers from twisted.internet import defer, reactor diff --git a/experiments/cursesio.py b/experiments/cursesio.py index 83b4a9f18..31fbda550 100644 --- a/experiments/cursesio.py +++ b/experiments/cursesio.py @@ -1,3 +1,17 @@ +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import curses import curses.wrapper from curses.ascii import isprint diff --git a/experiments/test_messaging.py b/experiments/test_messaging.py index 9a4542517..f4ae71bfc 100644 --- a/experiments/test_messaging.py +++ b/experiments/test_messaging.py @@ -1,4 +1,18 @@ # -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """ This is an example of using the server to server implementation to do a basic chat style thing. It accepts commands from stdin and outputs to stdout. diff --git a/graph/graph.py b/graph/graph.py index c60077341..03af12cbb 100644 --- a/graph/graph.py +++ b/graph/graph.py @@ -1,3 +1,17 @@ +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import sqlite3 import pydot diff --git a/scripts/copyrighter.pl b/scripts/copyrighter.pl new file mode 100755 index 000000000..e476c9cc8 --- /dev/null +++ b/scripts/copyrighter.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl -pi +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +$copyright = < Date: Wed, 13 Aug 2014 11:09:30 +0200 Subject: [PATCH 05/17] Display image messages from the stream --- webclient/app.css | 8 ++++++++ webclient/room/room.html | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/webclient/app.css b/webclient/app.css index fd548c117..13cd19a2e 100644 --- a/webclient/app.css +++ b/webclient/app.css @@ -187,6 +187,14 @@ h1 { border: 0px ! important; } +.image { + display: block; + max-width:320px; + max-height:320px; + width: auto; + height: auto; +} + .bubble { padding: 6px; padding-left: 1em; diff --git a/webclient/room/room.html b/webclient/room/room.html index 276c3caa5..600bc14eb 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -32,7 +32,8 @@
{{ msg.content.msgtype === "m.emote" ? ("* " + (members[msg.user_id].displayname || msg.user_id) + " ") : "" }} - {{ msg.content.body }} + {{ msg.content.msgtype === "m.text" ? msg.content.body : "" }} + {{ msg.content.body }}
From c87e1f641858fbc2e6ed6b99ef05591a977bd4c4 Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Wed, 13 Aug 2014 11:42:28 +0200 Subject: [PATCH 06/17] Room: Added a text input to type an image URL in order to send an image message --- webclient/app.css | 4 ++-- webclient/components/matrix/matrix-service.js | 11 +++++++++++ webclient/room/room-controller.js | 13 ++++++++++++- webclient/room/room.html | 12 ++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/webclient/app.css b/webclient/app.css index 13cd19a2e..9a46613d4 100644 --- a/webclient/app.css +++ b/webclient/app.css @@ -43,7 +43,7 @@ h1 { } .inputBarTable tr td { - padding: 4px; + padding: 1px 4px; } .mainInput { @@ -118,7 +118,7 @@ h1 { overflow separetely. */ .room .page { - height: calc(100vh - 198px); + height: calc(100vh - 220px); } /*** Message table ***/ diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js index 5f1731c1a..f054bf301 100644 --- a/webclient/components/matrix/matrix-service.js +++ b/webclient/components/matrix/matrix-service.js @@ -197,6 +197,17 @@ angular.module('matrixService', []) return this.sendMessage(room_id, msg_id, content); }, + // Send an image message + sendImageMessage: function(room_id, image_url, image_alt, msg_id) { + var content = { + msgtype: "m.image", + url: image_url, + body: image_alt + }; + + return this.sendMessage(room_id, msg_id, content); + }, + // Send an emote message sendEmoteMessage: function(room_id, body, msg_id) { var content = { diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index 7cb6cba65..cbd5c1a17 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -27,7 +27,8 @@ angular.module('RoomController', []) $scope.messages = []; $scope.members = {}; $scope.stopPoll = false; - + + $scope.imageURLToSend = ""; $scope.userIDToInvite = ""; var shortPoll = function() { @@ -224,6 +225,16 @@ angular.module('RoomController', []) }); }; + $scope.sendImage = function(url) { + matrixService.sendImageMessage($scope.room_id, url).then( + function() { + console.log("Image sent"); + }, + function(reason) { + $scope.feedback = "Failed to send image: " + reason; + }); + }; + $scope.$on('$destroy', function(e) { console.log("onDestroyed: Stopping poll."); $scope.stopPoll = true; diff --git a/webclient/room/room.html b/webclient/room/room.html index 600bc14eb..9cd1ec364 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -63,6 +63,18 @@ {{ feedback }} + + + + + + + + + + + + From 2ab77a007394b286e6d82d464f2b336d412b2134 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Aug 2014 11:48:55 +0100 Subject: [PATCH 07/17] fix footnotes a bit --- README.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index ce0d51036..2885c9f2f 100644 --- a/README.rst +++ b/README.rst @@ -51,9 +51,11 @@ https://github.com/matrix-org/synapse/issues or at matrix@matrix.org. Thanks for trying Matrix! -.. [1] VoIP currently in development -.. [2] Cryptographic signing of messages isn't turned on yet -.. [3] End-to-end encryption is currently in development +[1] VoIP currently in development + +[2] Cryptographic signing of messages isn't turned on yet + +[3] End-to-end encryption is currently in development Quick Start =========== From 9b3702c9240ed533ccf9f08ba666103234a53c6c Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 13 Aug 2014 11:57:49 +0100 Subject: [PATCH 08/17] Return the room_alias when GETing public rooms. --- synapse/storage/room.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/synapse/storage/room.py b/synapse/storage/room.py index 09d9c2339..a97162831 100644 --- a/synapse/storage/room.py +++ b/synapse/storage/room.py @@ -93,7 +93,10 @@ class RoomStore(SQLBaseStore): latest_topic = ("SELECT max(room_data.id) FROM room_data WHERE " + "room_data.type = ? GROUP BY room_id") - query = ("SELECT rooms.*, room_data.content FROM rooms LEFT JOIN " + query = ("SELECT rooms.*, room_data.content, room_alias FROM rooms " + + "LEFT JOIN " + + "room_aliases ON room_aliases.room_id = rooms.room_id " + + "LEFT JOIN " + "room_data ON rooms.room_id = room_data.room_id WHERE " + "(room_data.id IN (" + latest_topic + ") " + "OR room_data.id IS NULL) AND rooms.is_public = ?") @@ -103,7 +106,7 @@ class RoomStore(SQLBaseStore): ) # return only the keys the specification expects - ret_keys = ["room_id", "topic"] + ret_keys = ["room_id", "topic", "room_alias"] # extract topic from the json (icky) FIXME for i, room_row in enumerate(res): From 2a0f7541c73569139edb1dd6e0ffc0bff275c816 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Aug 2014 12:06:58 +0100 Subject: [PATCH 09/17] verbose by default please --- synapse/app/homeserver.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 9ad8ac7f0..aaa5c4465 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -89,12 +89,12 @@ def setup_logging(verbosity=0, filename=None, config_path=None): ) if not verbosity or verbosity == 0: - level = logging.WARNING - elif verbosity == 1: level = logging.INFO - else: + elif verbosity == 1: level = logging.DEBUG + # FIXME: we need a logging.WARN for a -q quiet option + logging.basicConfig(level=level, filename=filename, format=log_format) else: logging.config.fileConfig(config_path) From 7f40fa1d4601960e8c1ea39af26a3e7515ff0f3e Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 13 Aug 2014 13:50:01 +0100 Subject: [PATCH 10/17] Added a -w flag which will host the web client if specified. Currently this just delegates to the webclient RestServlet. --- synapse/app/homeserver.py | 4 +++- synapse/rest/__init__.py | 8 ++++++- synapse/rest/base.py | 42 ------------------------------------ synapse/rest/webclient.py | 45 +++++++++++++++++++++++++++++++++++++++ synapse/server.py | 14 ++++++++---- 5 files changed, 65 insertions(+), 48 deletions(-) create mode 100644 synapse/rest/webclient.py diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 9ad8ac7f0..dcf0b5f28 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -126,6 +126,8 @@ def setup(): parser.add_argument('--pid-file', dest="pid", help="When running as a " "daemon, the file to store the pid in", default="hs.pid") + parser.add_argument("-w", "--webclient", dest="webclient", + action="store_true", help="Host the web client.") args = parser.parse_args() verbosity = int(args.verbose) if args.verbose else None @@ -147,7 +149,7 @@ def setup(): # the replication layer hs.get_federation() - hs.register_servlets() + hs.register_servlets(host_web_client=args.webclient) hs.get_http_server().start_listening(args.port) diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py index b7f0c1fd2..74a372e2f 100644 --- a/synapse/rest/__init__.py +++ b/synapse/rest/__init__.py @@ -15,9 +15,11 @@ from . import ( - room, events, register, login, profile, public, presence, im, directory + room, events, register, login, profile, public, presence, im, directory, + webclient ) + class RestServletFactory(object): """ A factory for creating REST servlets. @@ -42,3 +44,7 @@ class RestServletFactory(object): presence.register_servlets(hs, http_server) im.register_servlets(hs, http_server) directory.register_servlets(hs, http_server) + + def register_web_client(self, hs): + http_server = hs.get_http_server() + webclient.register_servlets(hs, http_server) diff --git a/synapse/rest/base.py b/synapse/rest/base.py index 2f1ab57c7..65d417f75 100644 --- a/synapse/rest/base.py +++ b/synapse/rest/base.py @@ -30,48 +30,6 @@ def client_path_pattern(path_regex): return re.compile("^/matrix/client/api/v1" + path_regex) -class RestServletFactory(object): - - """ A factory for creating REST servlets. - - These REST servlets represent the entire client-server REST API. Generally - speaking, they serve as wrappers around events and the handlers that - process them. - - See synapse.api.events for information on synapse events. - """ - - def __init__(self, hs): - http_server = hs.get_http_server() - - # You get import errors if you try to import before the classes in this - # file are defined, hence importing here instead. - - import room - room.register_servlets(hs, http_server) - - import events - events.register_servlets(hs, http_server) - - import register - register.register_servlets(hs, http_server) - - import profile - profile.register_servlets(hs, http_server) - - import public - public.register_servlets(hs, http_server) - - import presence - presence.register_servlets(hs, http_server) - - import im - im.register_servlets(hs, http_server) - - import login - login.register_servlets(hs, http_server) - - class RestServlet(object): """ A Synapse REST Servlet. diff --git a/synapse/rest/webclient.py b/synapse/rest/webclient.py new file mode 100644 index 000000000..75a425c14 --- /dev/null +++ b/synapse/rest/webclient.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from synapse.rest.base import RestServlet + +import logging +import re + +logger = logging.getLogger(__name__) + + +class WebClientRestServlet(RestServlet): + # No PATTERN; we have custom dispatch rules here + + def register(self, http_server): + http_server.register_path("GET", + re.compile("^/$"), + self.on_GET_redirect) + http_server.register_path("GET", + re.compile("^/matrix/client$"), + self.on_GET) + + def on_GET(self, request): + return (200, "not implemented") + + def on_GET_redirect(self, request): + request.setHeader("Location", request.uri + "matrix/client") + return (302, None) + + +def register_servlets(hs, http_server): + logger.info("Registering web client.") + WebClientRestServlet(hs).register(http_server) \ No newline at end of file diff --git a/synapse/server.py b/synapse/server.py index 4ba203ac3..ba9022f32 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -171,7 +171,13 @@ class HomeServer(BaseHomeServer): def build_distributor(self): return Distributor() - def register_servlets(self): - """Simply building the ServletFactory is sufficient to have it - register.""" - self.get_rest_servlet_factory() + def register_servlets(self, host_web_client): + """ Register all servlets associated with this HomeServer. + + Args: + host_web_client (bool): True to host the web client as well. + """ + # Simply building the ServletFactory is sufficient to have it register + factory = self.get_rest_servlet_factory() + if host_web_client: + factory.register_web_client(self) From 55944ccf72882ae83dcf17a8013c63c49e51581d Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Wed, 13 Aug 2014 14:31:48 +0100 Subject: [PATCH 11/17] Use strings instead of opaque magic-number constants for presence states; rename AWAY to UNAVAILABLE --- synapse/api/constants.py | 8 ++++---- tests/handlers/test_presence.py | 24 ++++++++++++------------ tests/handlers/test_presencelike.py | 12 ++++++------ tests/rest/test_presence.py | 12 ++++++------ webclient/app.css | 2 +- webclient/room/room-controller.js | 11 ++++------- webclient/room/room.html | 2 +- 7 files changed, 34 insertions(+), 37 deletions(-) diff --git a/synapse/api/constants.py b/synapse/api/constants.py index 29687c348..1ff1af76e 100644 --- a/synapse/api/constants.py +++ b/synapse/api/constants.py @@ -37,7 +37,7 @@ class Feedback(object): class PresenceState(object): """Represents the presence state of a user.""" - OFFLINE = 0 - BUSY = 1 - ONLINE = 2 - FREE_FOR_CHAT = 3 + OFFLINE = u"offline" + UNAVAILABLE = u"unavailable" + ONLINE = u"online" + FREE_FOR_CHAT = u"free_for_chat" diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py index e7102e4ab..2299a2a7b 100644 --- a/tests/handlers/test_presence.py +++ b/tests/handlers/test_presence.py @@ -27,7 +27,7 @@ from synapse.handlers.presence import PresenceHandler, UserPresenceCache OFFLINE = PresenceState.OFFLINE -BUSY = PresenceState.BUSY +UNAVAILABLE = PresenceState.UNAVAILABLE ONLINE = PresenceState.ONLINE @@ -149,12 +149,12 @@ class PresenceStateTestCase(unittest.TestCase): yield self.handler.set_state( target_user=self.u_apple, auth_user=self.u_apple, - state={"state": BUSY, "status_msg": "Away"}) + state={"state": UNAVAILABLE, "status_msg": "Away"}) mocked_set.assert_called_with("apple", - {"state": 1, "status_msg": "Away"}) + {"state": UNAVAILABLE, "status_msg": "Away"}) self.mock_start.assert_called_with(self.u_apple, - state={"state": 1, "status_msg": "Away"}) + state={"state": UNAVAILABLE, "status_msg": "Away"}) yield self.handler.set_state( target_user=self.u_apple, auth_user=self.u_apple, @@ -555,7 +555,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@apple:test", - "state": 2}, + "state": "online"}, ], }), call( @@ -564,7 +564,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@apple:test", - "state": 2}, + "state": "online"}, ], }) ], any_order=True) @@ -582,7 +582,7 @@ class PresencePushTestCase(unittest.TestCase): "remote", "m.presence", { "push": [ {"user_id": "@potato:remote", - "state": 2}, + "state": "online"}, ], } ) @@ -646,7 +646,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@apple:test", - "state": 2}, + "state": "online"}, ], }), call( @@ -655,7 +655,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@banana:test", - "state": 0}, + "state": "offline"}, ], }), ], any_order=True) @@ -666,7 +666,7 @@ class PresencePushTestCase(unittest.TestCase): self.handler._user_cachemap[self.u_clementine] = UserPresenceCache() self.handler._user_cachemap[self.u_clementine].update( - {"state": PresenceState.ONLINE}, self.u_clementine) + {"state": ONLINE}, self.u_clementine) self.room_members.append(self.u_potato) yield self.distributor.fire("user_joined_room", self.u_clementine, @@ -680,7 +680,7 @@ class PresencePushTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@clementine:test", - "state": 2}, + "state": "online"}, ], }), ) @@ -882,7 +882,7 @@ class PresencePollingTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@banana:test", - "state": 0, + "state": "offline", "status_msg": None}, ], }, diff --git a/tests/handlers/test_presencelike.py b/tests/handlers/test_presencelike.py index 12b7dca00..224cf646f 100644 --- a/tests/handlers/test_presencelike.py +++ b/tests/handlers/test_presencelike.py @@ -29,7 +29,7 @@ from synapse.handlers.profile import ProfileHandler OFFLINE = PresenceState.OFFLINE -BUSY = PresenceState.BUSY +UNAVAILABLE = PresenceState.UNAVAILABLE ONLINE = PresenceState.ONLINE @@ -125,12 +125,12 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase): yield self.handlers.presence_handler.set_state( target_user=self.u_apple, auth_user=self.u_apple, - state={"state": BUSY, "status_msg": "Away"}) + state={"state": UNAVAILABLE, "status_msg": "Away"}) mocked_set.assert_called_with("apple", - {"state": 1, "status_msg": "Away"}) + {"state": UNAVAILABLE, "status_msg": "Away"}) self.mock_start.assert_called_with(self.u_apple, - state={"state": 1, "status_msg": "Away", + state={"state": UNAVAILABLE, "status_msg": "Away", "displayname": "Frank", "avatar_url": "http://foo"}) @@ -220,7 +220,7 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase): content={ "push": [ {"user_id": "@apple:test", - "state": 2, + "state": "online", "displayname": "Frank", "avatar_url": "http://foo"}, ], @@ -238,7 +238,7 @@ class PresenceProfilelikeDataTestCase(unittest.TestCase): "remote", "m.presence", { "push": [ {"user_id": "@potato:remote", - "state": 2, + "state": "online", "displayname": "Frank", "avatar_url": "http://foo"}, ], diff --git a/tests/rest/test_presence.py b/tests/rest/test_presence.py index 5b1e060c5..7c54e067c 100644 --- a/tests/rest/test_presence.py +++ b/tests/rest/test_presence.py @@ -31,7 +31,7 @@ logging.getLogger().addHandler(logging.NullHandler()) OFFLINE = PresenceState.OFFLINE -BUSY = PresenceState.BUSY +UNAVAILABLE = PresenceState.UNAVAILABLE ONLINE = PresenceState.ONLINE @@ -69,7 +69,7 @@ class PresenceStateTestCase(unittest.TestCase): def test_get_my_status(self): mocked_get = self.mock_handler.get_state mocked_get.return_value = defer.succeed( - {"state": 2, "status_msg": "Available"}) + {"state": ONLINE, "status_msg": "Available"}) (code, response) = yield self.mock_server.trigger("GET", "/presence/%s/status" % (myid), None) @@ -87,12 +87,12 @@ class PresenceStateTestCase(unittest.TestCase): (code, response) = yield self.mock_server.trigger("PUT", "/presence/%s/status" % (myid), - '{"state": 1, "status_msg": "Away"}') + '{"state": "unavailable", "status_msg": "Away"}') self.assertEquals(200, code) mocked_set.assert_called_with(target_user=self.u_apple, auth_user=self.u_apple, - state={"state": 1, "status_msg": "Away"}) + state={"state": UNAVAILABLE, "status_msg": "Away"}) class PresenceListTestCase(unittest.TestCase): @@ -234,7 +234,7 @@ class PresenceEventStreamTestCase(unittest.TestCase): # I'll already get my own presence state change self.assertEquals({"start": "0", "end": "1", "chunk": [ {"type": "m.presence", - "content": {"user_id": "@apple:test", "state": 2}}, + "content": {"user_id": "@apple:test", "state": ONLINE}}, ]}, response) self.mock_datastore.set_presence_state.return_value = defer.succeed( @@ -251,5 +251,5 @@ class PresenceEventStreamTestCase(unittest.TestCase): self.assertEquals(200, code) self.assertEquals({"start": "1", "end": "2", "chunk": [ {"type": "m.presence", - "content": {"user_id": "@banana:test", "state": 2}}, + "content": {"user_id": "@banana:test", "state": ONLINE}}, ]}, response) diff --git a/webclient/app.css b/webclient/app.css index 9a46613d4..15b6c9130 100644 --- a/webclient/app.css +++ b/webclient/app.css @@ -106,7 +106,7 @@ h1 { background-color: #38AF00; } -.away { +.unavailable { background-color: #FFCC00; } diff --git a/webclient/room/room-controller.js b/webclient/room/room-controller.js index cbd5c1a17..5d1c65641 100644 --- a/webclient/room/room-controller.js +++ b/webclient/room/room-controller.js @@ -123,17 +123,14 @@ angular.module('RoomController', []) var member = $scope.members[chunk.content.user_id]; if ("state" in chunk.content) { - var ONLINE = 2; - var AWAY = 1; - var OFFLINE = 0; - if (chunk.content.state === ONLINE) { + if (chunk.content.state === "online") { member.presenceState = "online"; } - else if (chunk.content.state === OFFLINE) { + else if (chunk.content.state === "offline") { member.presenceState = "offline"; } - else if (chunk.content.state === AWAY) { - member.presenceState = "away"; + else if (chunk.content.state === "unavailable") { + member.presenceState = "unavailable"; } } diff --git a/webclient/room/room.html b/webclient/room/room.html index 9cd1ec364..5de2190b8 100644 --- a/webclient/room/room.html +++ b/webclient/room/room.html @@ -14,7 +14,7 @@
{{ info.displayname || name }}
- + From cf965af3c5d233a1d62887d991d3a4e8996dbf70 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 13 Aug 2014 14:40:47 +0100 Subject: [PATCH 12/17] Add troubleshooting section to help with PyNaCl bug. --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index 2885c9f2f..49c210599 100644 --- a/README.rst +++ b/README.rst @@ -297,3 +297,9 @@ sphinxcontrib-napoleon:: Building internal API documentation:: $ python setup.py build_sphinx + +Troubleshooting +=============== + +fatal error: sodium.h: No such file or directory + There is a bug in PyNaCl 0.2.3 which can cause the module to fail to import. The bug is fixed in HEAD so you can work around it by checking PyNaCl out of git directly (https://github.com/pyca/pynacl) and installing it. Installing PyNaCl using pip may also work (remember to remove any other versions installed by setuputils in, for example, ~/.local/lib). From 820ed34abefafd43e9853d147606a8231d4d909f Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Wed, 13 Aug 2014 15:07:49 +0100 Subject: [PATCH 13/17] Namespace all the Federation HTTP URLs to /matrix/federation/v1/... --- docs/server-server/specification.rst | 14 +++++++----- synapse/federation/transport.py | 33 +++++++++++++++------------- tests/federation/test_federation.py | 15 +++++++------ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/docs/server-server/specification.rst b/docs/server-server/specification.rst index e1e49cc06..a386bd3e7 100644 --- a/docs/server-server/specification.rst +++ b/docs/server-server/specification.rst @@ -116,9 +116,13 @@ federation.]] Protocol URLs ============= +All these URLs are namespaced within a prefix of + + /matrix/federation/v1/... + For active pushing of messages representing live activity "as it happens": - PUT /send/:transaction_id/ + PUT .../send/:transaction_id/ Body: JSON encoding of a single Transaction Response: [[TODO(paul): I don't actually understand what @@ -132,7 +136,7 @@ For active pushing of messages representing live activity "as it happens": To fetch a particular PDU: - GET /pdu/:origin/:pdu_id/ + GET .../pdu/:origin/:pdu_id/ Response: JSON encoding of a single Transaction containing one PDU @@ -142,7 +146,7 @@ To fetch a particular PDU: To fetch all the state of a given context: - GET /state/:context/ + GET .../state/:context/ Response: JSON encoding of a single Transaction containing multiple PDUs @@ -153,7 +157,7 @@ To fetch all the state of a given context: To paginate events on a given context: - GET /paginate/:context/ + GET .../paginate/:context/ Query args: v, limit Response: JSON encoding of a single Transaction containing multiple PDUs @@ -167,7 +171,7 @@ To paginate events on a given context: To stream events all the events: - GET /pull/ + GET .../pull/ Query args: origin, v Response: JSON encoding of a single Transaction consisting of multiple PDUs diff --git a/synapse/federation/transport.py b/synapse/federation/transport.py index 09a5e5901..ff3fc3441 100644 --- a/synapse/federation/transport.py +++ b/synapse/federation/transport.py @@ -33,6 +33,9 @@ import re logger = logging.getLogger(__name__) +PREFIX = "/matrix/federation/v1" + + class TransportLayer(object): """This is a basic implementation of the transport layer that translates transactions and other requests to/from HTTP. @@ -84,9 +87,9 @@ class TransportLayer(object): logger.debug("get_context_state dest=%s, context=%s", destination, context) - path = "/state/%s/" % context + subpath = "/state/%s/" % context - return self._do_request_for_transaction(destination, path) + return self._do_request_for_transaction(destination, subpath) @log_function def get_pdu(self, destination, pdu_origin, pdu_id): @@ -104,9 +107,9 @@ class TransportLayer(object): logger.debug("get_pdu dest=%s, pdu_origin=%s, pdu_id=%s", destination, pdu_origin, pdu_id) - path = "/pdu/%s/%s/" % (pdu_origin, pdu_id) + subpath = "/pdu/%s/%s/" % (pdu_origin, pdu_id) - return self._do_request_for_transaction(destination, path) + return self._do_request_for_transaction(destination, subpath) @log_function def paginate(self, dest, context, pdu_tuples, limit): @@ -130,14 +133,14 @@ class TransportLayer(object): if not pdu_tuples: return - path = "/paginate/%s/" % context + subpath = "/paginate/%s/" % context args = {"v": ["%s,%s" % (i, o) for i, o in pdu_tuples]} args["limit"] = limit return self._do_request_for_transaction( dest, - path, + subpath, args=args, ) @@ -166,7 +169,7 @@ class TransportLayer(object): code, response = yield self.client.put_json( transaction.destination, - path="/send/%s/" % transaction.transaction_id, + path=PREFIX + "/send/%s/" % transaction.transaction_id, data=data ) @@ -189,7 +192,7 @@ class TransportLayer(object): # This is when someone is trying to send us a bunch of data. self.server.register_path( "PUT", - re.compile("^/send/([^/]*)/$"), + re.compile("^" + PREFIX + "/send/([^/]*)/$"), self._on_send_request ) @@ -207,7 +210,7 @@ class TransportLayer(object): # This is for when someone asks us for everything since version X self.server.register_path( "GET", - re.compile("^/pull/$"), + re.compile("^" + PREFIX + "/pull/$"), lambda request: handler.on_pull_request( request.args["origin"][0], request.args["v"] @@ -218,7 +221,7 @@ class TransportLayer(object): # data_id pair. self.server.register_path( "GET", - re.compile("^/pdu/([^/]*)/([^/]*)/$"), + re.compile("^" + PREFIX + "/pdu/([^/]*)/([^/]*)/$"), lambda request, pdu_origin, pdu_id: handler.on_pdu_request( pdu_origin, pdu_id ) @@ -227,7 +230,7 @@ class TransportLayer(object): # This is when someone asks for all data for a given context. self.server.register_path( "GET", - re.compile("^/state/([^/]*)/$"), + re.compile("^" + PREFIX + "/state/([^/]*)/$"), lambda request, context: handler.on_context_state_request( context ) @@ -235,7 +238,7 @@ class TransportLayer(object): self.server.register_path( "GET", - re.compile("^/paginate/([^/]*)/$"), + re.compile("^" + PREFIX + "/paginate/([^/]*)/$"), lambda request, context: self._on_paginate_request( context, request.args["v"], request.args["limit"] @@ -244,7 +247,7 @@ class TransportLayer(object): self.server.register_path( "GET", - re.compile("^/context/([^/]*)/$"), + re.compile("^" + PREFIX + "/context/([^/]*)/$"), lambda request, context: handler.on_context_pdus_request(context) ) @@ -300,7 +303,7 @@ class TransportLayer(object): @defer.inlineCallbacks @log_function - def _do_request_for_transaction(self, destination, path, args={}): + def _do_request_for_transaction(self, destination, subpath, args={}): """ Args: destination (str) @@ -313,7 +316,7 @@ class TransportLayer(object): data = yield self.client.get_json( destination, - path=path, + path=PREFIX + subpath, args=args, ) diff --git a/tests/federation/test_federation.py b/tests/federation/test_federation.py index 99b15b226..f493ee253 100644 --- a/tests/federation/test_federation.py +++ b/tests/federation/test_federation.py @@ -96,7 +96,7 @@ class FederationTestCase(unittest.TestCase): # Empty context initially (code, response) = yield self.mock_http_server.trigger("GET", - "/state/my-context/", None) + "/matrix/federation/v1/state/my-context/", None) self.assertEquals(200, code) self.assertFalse(response["pdus"]) @@ -121,7 +121,7 @@ class FederationTestCase(unittest.TestCase): ) (code, response) = yield self.mock_http_server.trigger("GET", - "/state/my-context/", None) + "/matrix/federation/v1/state/my-context/", None) self.assertEquals(200, code) self.assertEquals(1, len(response["pdus"])) @@ -132,7 +132,7 @@ class FederationTestCase(unittest.TestCase): ) (code, response) = yield self.mock_http_server.trigger("GET", - "/pdu/red/abc123def456/", None) + "/matrix/federation/v1/pdu/red/abc123def456/", None) self.assertEquals(404, code) # Now insert such a PDU @@ -151,7 +151,7 @@ class FederationTestCase(unittest.TestCase): ) (code, response) = yield self.mock_http_server.trigger("GET", - "/pdu/red/abc123def456/", None) + "/matrix/federation/v1/pdu/red/abc123def456/", None) self.assertEquals(200, code) self.assertEquals(1, len(response["pdus"])) self.assertEquals("m.text", response["pdus"][0]["pdu_type"]) @@ -177,7 +177,7 @@ class FederationTestCase(unittest.TestCase): self.mock_http_client.put_json.assert_called_with( "remote", - path="/send/1000000/", + path="/matrix/federation/v1/send/1000000/", data={ "ts": 1000000, "origin": "test", @@ -212,7 +212,7 @@ class FederationTestCase(unittest.TestCase): # MockClock ensures we can guess these timestamps self.mock_http_client.put_json.assert_called_with( "remote", - path="/send/1000000/", + path="/matrix/federation/v1/send/1000000/", data={ "origin": "test", "ts": 1000000, @@ -234,7 +234,8 @@ class FederationTestCase(unittest.TestCase): self.federation.register_edu_handler("m.test", recv_observer) - yield self.mock_http_server.trigger("PUT", "/send/1001000/", + yield self.mock_http_server.trigger("PUT", + "/matrix/federation/v1/send/1001000/", """{ "origin": "remote", "ts": 1001000, From b370f9903ce487edb71ae32956b2782f0799283e Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Wed, 13 Aug 2014 15:14:22 +0100 Subject: [PATCH 14/17] Fix logging verbosity parsing code --- synapse/app/homeserver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index aaa5c4465..5e126bc87 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -88,9 +88,8 @@ def setup_logging(verbosity=0, filename=None, config_path=None): '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s' ) - if not verbosity or verbosity == 0: - level = logging.INFO - elif verbosity == 1: + level = logging.INFO + if verbosity: level = logging.DEBUG # FIXME: we need a logging.WARN for a -q quiet option From 31f2ec252c7e08c8ef7a04efb0fa321f7d9f39d5 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Aug 2014 15:23:06 +0100 Subject: [PATCH 15/17] refactor the README a load more to make the quickstart more visible --- MAP.rst | 35 ++++++++++++++ README.rst | 132 +++++++++++++++++++---------------------------------- 2 files changed, 83 insertions(+), 84 deletions(-) create mode 100644 MAP.rst diff --git a/MAP.rst b/MAP.rst new file mode 100644 index 000000000..0f8e9818a --- /dev/null +++ b/MAP.rst @@ -0,0 +1,35 @@ +Directory Structure +=================== + +Warning: this may be a bit stale... + +:: + + . + ├── cmdclient Basic CLI python Matrix client + ├── demo Scripts for running standalone Matrix demos + ├── docs All doc, including the draft Matrix API spec + │   ├── client-server The client-server Matrix API spec + │   ├── model Domain-specific elements of the Matrix API spec + │   ├── server-server The server-server model of the Matrix API spec + │   └── sphinx The internal API doc of the Synapse homeserver + ├── experiments Early experiments of using Synapse's internal APIs + ├── graph Visualisation of Matrix's distributed message store + ├── synapse The reference Matrix homeserver implementation + │   ├── api Common building blocks for the APIs + │   │   ├── events Definition of state representation Events + │   │   └── streams Definition of streamable Event objects + │   ├── app The __main__ entry point for the homeserver + │   ├── crypto The PKI client/server used for secure federation + │   │   └── resource PKI helper objects (e.g. keys) + │   ├── federation Server-server state replication logic + │   ├── handlers The main business logic of the homeserver + │   ├── http Wrappers around Twisted's HTTP server & client + │   ├── rest Servlet-style RESTful API + │   ├── storage Persistence subsystem (currently only sqlite3) + │   │   └── schema sqlite persistence schema + │   └── util Synapse-specific utilities + ├── tests Unit tests for the Synapse homeserver + └── webclient Basic AngularJS Matrix web client + + diff --git a/README.rst b/README.rst index 49c210599..8bfedfb0c 100644 --- a/README.rst +++ b/README.rst @@ -1,16 +1,47 @@ -About -===== +Quick Start +=========== Matrix is an ambitious new ecosystem for open federated Instant Messaging and -VoIP[1]. +VoIP[1]. The basics you need to know to get up and running are: -Matrix specifies a set of pragmatic RESTful HTTP JSON APIs as an open standard, -providing: + - Chatrooms look like ``#matrix:matrix.org`` or ``#test:localhost:8080`` + + - Matrix user IDs look like ``@matthew:matrix.org`` (although in the future + you will normally refer to yourself and others using a 3PID: email + address, phone number, etc rather than manipulating matrix user IDs) + + + +To get up and running: + + - To simply play with an **existing** homeserver you can + just go straight to http://matrix.org/alpha. + + - To run your own **private** homeserver on localhost:8080, install synapse + with ``python setup.py develop --user`` and then run one with + ``python synapse/app/homeserver.py`` + + - To run your own webclient: + ``cd webclient; python -m SimpleHTTPServer`` and hit http://localhost:8000 + in your web browser (a recent Chrome, Safari or Firefox for now, + please...) + + - To quickly run a **public** homeserver that can exchange messages with + other homeservers and participate in the overall Matrix federation, open + up port 8080 and run ``python synapse/app/homeserver.py --host + machine.my.domain.name``. Then come join ``#matrix:matrix.org`` and + say hi! :) + +About Matrix +============ + +Matrix specifies a set of pragmatic RESTful HTTP JSON APIs for VoIP and IM as an +open standard, providing: - Creating and managing fully distributed chat rooms with no single points of control or failure - Eventually-consistent cryptographically secure[2] synchronisation of room - state across a global open network of federated servers and services + state across a global open network of federated servers and services - Sending and receiving extensible messages in a room with (optional) end-to-end encryption[3] - Inviting, joining, leaving, kicking, banning room members @@ -57,74 +88,6 @@ Thanks for trying Matrix! [3] End-to-end encryption is currently in development -Quick Start -=========== - -The basics you need to know about Matrix are: - - - Chatrooms look like ``#matrix:matrix.org`` or ``#test:localhost:8080`` - - - Matrix user IDs look like ``@matthew:matrix.org`` (although in the future - you will normally refer to yourself and others using a 3PID: email - address, phone number, etc rather than manipulating matrix user IDs) - - - To simply play with an **existing** homeserver (e.g. matrix.org), you can - just go straight to http://matrix.org/alpha, specify a homeserver - (defaults to matrix.org) and sign up and use it. (Sign-up security is - currently work-in-progress) - - - To run your own **private** homeserver on localhost:8080, install synapse - with ``python setup.py develop --user`` and then run one with - ``python synapse/app/homeserver.py`` - - - To run your own webclient: - ``cd webclient; python -m SimpleHTTPServer`` and hit http://localhost:8000 - in your web browser (a recent Chrome, Safari or Firefox for now, - please...) - - - For now, register some accounts like ``@testing:localhost:8080`` from - different browsers, join a room like ``#test:localhost:8080`` and have a - play. - - - To quickly run a **public** homeserver that can exchange messages with - other homeservers and participate in the overall Matrix federation, open - up port 8080 and run ``python synapse/app/homeserver.py --host - machine.my.domain.name``. Then come join ``#matrix:matrix.org`` and - say hi! :) - - -Directory Structure -=================== - -:: - - . - ├── cmdclient Basic CLI python Matrix client - ├── demo Scripts for running standalone Matrix demos - ├── docs All doc, including the draft Matrix API spec - │   ├── client-server The client-server Matrix API spec - │   ├── model Domain-specific elements of the Matrix API spec - │   ├── server-server The server-server model of the Matrix API spec - │   └── sphinx The internal API doc of the Synapse homeserver - ├── experiments Early experiments of using Synapse's internal APIs - ├── graph Visualisation of Matrix's distributed message store - ├── synapse The reference Matrix homeserver implementation - │   ├── api Common building blocks for the APIs - │   │   ├── events Definition of state representation Events - │   │   └── streams Definition of streamable Event objects - │   ├── app The __main__ entry point for the homeserver - │   ├── crypto The PKI client/server used for secure federation - │   │   └── resource PKI helper objects (e.g. keys) - │   ├── federation Server-server state replication logic - │   ├── handlers The main business logic of the homeserver - │   ├── http Wrappers around Twisted's HTTP server & client - │   ├── rest Servlet-style RESTful API - │   ├── storage Persistence subsystem (currently only sqlite3) - │   │   └── schema sqlite persistence schema - │   └── util Synapse-specific utilities - ├── tests Unit tests for the Synapse homeserver - └── webclient Basic AngularJS Matrix web client - Homeserver Installation ======================= @@ -151,6 +114,12 @@ may need to also run: $ sudo apt-get install python-pip $ sudo pip install --upgrade setuptools + +If you get errors about ``sodium.h`` being missing, you may also need to +manually install a newer PyNaCl via pip as setuptools installs an old one. Or +you can check PyNaCl out of git directly (https://github.com/pyca/pynacl) and +installing it. Installing PyNaCl using pip may also work (remember to remove any +other versions installed by setuputils in, for example, ~/.local/lib). This will run a process of downloading and installing into your user's .local/lib directory all of the required dependencies that are @@ -168,8 +137,8 @@ This should end with a 'PASSED' result:: PASSED (successes=143) -Running The Synapse Homeserver -============================== +Setting up Federation +===================== In order for other homeservers to send messages to your server, it will need to be publicly visible on the internet, and they will need to know its host name. @@ -215,7 +184,7 @@ Running a Demo Federation of Homeservers If you want to get up and running quickly with a trio of homeservers in a private federation (``localhost:8080``, ``localhost:8081`` and -``localhost:8082``) which you can then point a demo webclient at, simply run:: +``localhost:8082``) which you can then access through the webclient running at http://localhost:8080. Simply run:: $ demo/start.sh @@ -279,8 +248,8 @@ as the primary means of identity and E2E encryption is not complete. As such, we're not yet running an identity server in public. -How does it all work?! -====================== +Where's the spec?! +================== For now, please go spelunking in the ``docs/`` directory to find out. @@ -298,8 +267,3 @@ Building internal API documentation:: $ python setup.py build_sphinx -Troubleshooting -=============== - -fatal error: sodium.h: No such file or directory - There is a bug in PyNaCl 0.2.3 which can cause the module to fail to import. The bug is fixed in HEAD so you can work around it by checking PyNaCl out of git directly (https://github.com/pyca/pynacl) and installing it. Installing PyNaCl using pip may also work (remember to remove any other versions installed by setuputils in, for example, ~/.local/lib). From ecc299d45800295ea962a8218de8ca00d949c660 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Wed, 13 Aug 2014 15:37:57 +0100 Subject: [PATCH 16/17] more quickstart fixes --- README.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 8bfedfb0c..319bbb6e4 100644 --- a/README.rst +++ b/README.rst @@ -4,13 +4,18 @@ Quick Start Matrix is an ambitious new ecosystem for open federated Instant Messaging and VoIP[1]. The basics you need to know to get up and running are: - - Chatrooms look like ``#matrix:matrix.org`` or ``#test:localhost:8080`` + - Chatrooms are distributed and do not exist on any single server. Rooms + can be found using names like ``#matrix:matrix.org`` or + ``#test:localhost:8080`` or they can be ephemeral. - Matrix user IDs look like ``@matthew:matrix.org`` (although in the future you will normally refer to yourself and others using a 3PID: email address, phone number, etc rather than manipulating matrix user IDs) - - + +The overall architecture is:: + + client <----> homeserver <=================> homeserver <-----> client + e.g. matrix.org:8080 e.g. mydomain.net:8080 To get up and running: @@ -26,7 +31,7 @@ To get up and running: in your web browser (a recent Chrome, Safari or Firefox for now, please...) - - To quickly run a **public** homeserver that can exchange messages with + - To make the homeserver **public** and let it exchange messages with other homeservers and participate in the overall Matrix federation, open up port 8080 and run ``python synapse/app/homeserver.py --host machine.my.domain.name``. Then come join ``#matrix:matrix.org`` and From 2da1e1526ecff27a24de3701a8f472f53c7415e8 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 13 Aug 2014 15:57:58 +0100 Subject: [PATCH 17/17] Don't pass host_web_client flag to register_servlets, it needs to be a Resource not a RestServlet. --- synapse/app/homeserver.py | 2 +- synapse/server.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index f89b4652e..82afb04c7 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -148,7 +148,7 @@ def setup(): # the replication layer hs.get_federation() - hs.register_servlets(host_web_client=args.webclient) + hs.register_servlets() hs.get_http_server().start_listening(args.port) diff --git a/synapse/server.py b/synapse/server.py index ba9022f32..0211972d0 100644 --- a/synapse/server.py +++ b/synapse/server.py @@ -171,7 +171,7 @@ class HomeServer(BaseHomeServer): def build_distributor(self): return Distributor() - def register_servlets(self, host_web_client): + def register_servlets(self): """ Register all servlets associated with this HomeServer. Args: @@ -179,5 +179,3 @@ class HomeServer(BaseHomeServer): """ # Simply building the ServletFactory is sufficient to have it register factory = self.get_rest_servlet_factory() - if host_web_client: - factory.register_web_client(self)