Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AS-specific room publication API #306

Merged
merged 13 commits into from
Dec 13, 2016

Conversation

lukebarnard1
Copy link
Contributor

@lukebarnard1 lukebarnard1 commented Dec 12, 2016

Corresponds to the changes outlined here: matrix-org/synapse#1676

  • network_id (which is an IRC server.domain) has been added to each instance returned by /thirdparty/protocols.
  • When room visibility is changed, the new endpoint specifically for ASes is used, which specifies the network_id to be the server.domain of the first bridged channel in the list of channels mapped to that room.

This requires matrix-org/matrix-js-sdk#306

Luke Barnard added 3 commits December 12, 2016 13:38
This is the same as desc: server.config.name or if thats falsy, then server.domain. This is the same network_id that will be used in the new AS-specific room publishing API.
This requires the commit 742d942 from luke/feature-AS-room-publication
@lukebarnard1 lukebarnard1 changed the title Luke/api change public rooms Use AS-specific room publication API Dec 12, 2016
@lukebarnard1 lukebarnard1 requested a review from kegsay December 12, 2016 14:16
if (currentState !== correctState) {
return cli.setRoomDirectoryVisibility(roomId, correctState).then(
return cli.setRoomDirectoryVisibilityAppService(networkId, roomId, correctState).then(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work for the existing Freenode rooms on matrix.org which are not in a networked list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much in the same way it would work for those not in the main list.

@@ -181,8 +181,12 @@ PublicitySyncer.prototype._solveVisibility = Promise.coroutine(function*() {
let currentState = this._visibilityMap.roomVisibilities[roomId];
let correctState = shouldBePrivate(roomId, []) ? 'private' : 'public';

// Use the server domain of the first mapping
// 'localhost #channel1' => 'localhost'
const networkId = this._visibilityMap.mappings[roomId][0].split(' ')[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this._visibilityMap.mappings[roomId] guaranteed to be non-null? We seem to do a null guard on :140 but we don't here. But :127 makes me think that yes, it is guaranteed to be non-null. But then why the null guard on :140? Some clarification here would be good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, ignoring the null guard issue, will there always be a mapped channel for this room ID? Now that I think is no, which would then NPE on this line.

Copy link
Contributor Author

@lukebarnard1 lukebarnard1 Dec 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null guard shouldn't be needed, you're right (it didn't originate for any particular reason, I checked in it's blame history). And yes the mappings are guaranteed to be set for a room, and contain at least one channel mapping otherwise that room wouldn't be in the RoomStore, and thus wouldn't be returned by getAllChannelMappings.

But I'd be happy to null guard just in case.

@kegsay
Copy link
Member

kegsay commented Dec 12, 2016

Otherwise LGTM

@@ -560,6 +560,7 @@ IrcBridge.prototype.getThirdPartyProtocol = function(protocol) {
},
instances: servers.map((server) => {
return {
network_id: server.domain,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this change? e.g. if we change the domain we use to connect to a network? Its important that that this remains constant unless the AS republishes all the rooms after a change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's rare, but it can change like when we hop to IPv6 from IPv4. We may want to indirect here (e.g. have a network_id value in the config file, but default to server.domain if one is not supplied).

This becomes relevant when we inevitably move Moznet to v6 (it's still v4 atm).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had totally forgotten about this. I shall add network_id to the config.

Luke Barnard added 3 commits December 12, 2016 16:29
Instead of keying of the server domain for publicity syncing, use a network ID which should be unique amongst the servers being bridged to allow the server domain being changed without public room lists being affected. This networkId could be used in future as a way to key servers on the bridge, although because they are defined as strings they are not guaranteed to be unique.
@@ -31,6 +31,9 @@ ircService:
# A human-readable description string
# description: "Example.com IRC network"

# An ID for uniquely identifying this server amongst other servers being bridged.
networkId: "example"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this in a comment like the description field is, as most people need not care about this field.

* bridge across all servers/instances. Defaults to the domain of the server.
*/
IrcServer.prototype.getNetworkId = function() {
return this.config.networkId || server.domain;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's a server? :)

@@ -34,6 +34,14 @@ IrcServer.prototype.getReadableName = function() {
}

/**
* Return the network ID of this server, which should be unique for this
* bridge across all servers/instances. Defaults to the domain of the server.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSDoc please.

@@ -170,7 +170,7 @@ DataStore.prototype.getAllChannelMappings = Promise.coroutine(function*() {
(e) => e.matrix_id === roomId
).map((e) => {
return {
domain: e.remote.domain,
networkId: this._serverMappings[e.remote.domain],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the response object without updating docs. Please update docs.

@@ -573,7 +573,7 @@ IrcHandler.prototype.onMode = Promise.coroutine(function*(req, server, channel,
}
// Update the visibility for all rooms connected to this channel
return this.ircBridge.publicitySyncer.updateVisibilityMap(
true, server.domain + ' ' + channel, enabled
true, server.getNetworkId() + ' ' + channel, enabled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like this. I didn't say anything at the time but I'm in a less accepting mood today. I appreciate that the publicity syncer needs to key off a tuple of network ID + channel. I don't feel it is the caller's responsibility to craft the unique key. We should be calling a method which accepts a server and channel and returns the key, so we can consistently apply the concatenation rules. Otherwise, as I'm sure you now appreciate, you need to find alllll the places where we make the key and change them in the same way in order to apply a fix, which makes it really really easy to miss one place. See https://github.com/matrix-org/matrix-appservice-irc/blob/master/lib/DataStore.js#L484 for an example.

@lukebarnard1 lukebarnard1 requested a review from kegsay December 13, 2016 10:16
@@ -125,7 +140,7 @@ PublicitySyncer.prototype._solveVisibility = Promise.coroutine(function*() {

roomIds.forEach((roomId) => {
this._visibilityMap.mappings[roomId] = mappings[roomId].map((mapping) => {
return mapping.domain + ' ' + mapping.channel
return mapping.networkId + ' ' + mapping.channel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be calling getIRCVisMapKey?

@kegsay
Copy link
Member

kegsay commented Dec 13, 2016

Otherwise LGTM

@@ -140,7 +141,7 @@ PublicitySyncer.prototype._solveVisibility = Promise.coroutine(function*() {

roomIds.forEach((roomId) => {
this._visibilityMap.mappings[roomId] = mappings[roomId].map((mapping) => {
return mapping.networkId + ' ' + mapping.channel
return getIRCVisMapKey(mapping.networkId, mapping.channel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot a this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants