-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve: Support search and adding federated users through regular en…
…dpoints (#13936)
- Loading branch information
1 parent
be8ae64
commit 65b5be3
Showing
25 changed files
with
330 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { HTTP } from 'meteor/http'; | ||
|
||
import { logger } from '../logger'; | ||
import { Federation } from '../'; | ||
|
||
import { skipRetryOnSpecificError, delay } from './utils'; | ||
|
||
export class PeerHTTP { | ||
constructor() { | ||
this.config = {}; | ||
} | ||
|
||
setConfig(config) { | ||
// General | ||
this.config = config; | ||
} | ||
|
||
log(message) { | ||
logger.http.info(message); | ||
} | ||
|
||
// | ||
// Direct request | ||
simpleRequest(peer, method, uri, body, headers) { | ||
this.log(`Request: ${ method } ${ uri }`); | ||
|
||
const { url: serverBaseURL } = peer; | ||
|
||
const url = `${ serverBaseURL }${ uri }`; | ||
|
||
let data = null; | ||
|
||
if (method === 'POST' || method === 'PUT') { | ||
data = body; | ||
} | ||
|
||
this.log(`Sending request: ${ method } - ${ uri }`); | ||
|
||
return HTTP.call(method, url, { data, timeout: 2000, headers: { ...headers, 'x-federation-domain': this.config.peer.domain } }); | ||
} | ||
|
||
// | ||
// Request trying to find DNS entries | ||
request(peer, method, uri, body, retryInfo = {}, headers = {}) { | ||
// Normalize retry info | ||
retryInfo = { | ||
total: retryInfo.total || 1, | ||
stepSize: retryInfo.stepSize || 100, | ||
stepMultiplier: retryInfo.stepMultiplier || 1, | ||
tryToUpdateDNS: retryInfo.tryToUpdateDNS === undefined ? true : retryInfo.tryToUpdateDNS, | ||
DNSUpdated: false, | ||
}; | ||
|
||
for (let i = 0; i <= retryInfo.total; i++) { | ||
try { | ||
return this.simpleRequest(peer, method, uri, body, headers); | ||
} catch (err) { | ||
try { | ||
if (retryInfo.tryToUpdateDNS && !retryInfo.DNSUpdated) { | ||
i--; | ||
|
||
retryInfo.DNSUpdated = true; | ||
|
||
this.log(`Trying to update local DNS cache for peer:${ peer.domain }`); | ||
|
||
peer = Federation.peerDNS.updatePeerDNS(peer.domain); | ||
|
||
continue; | ||
} | ||
} catch (err) { | ||
if (err.response && err.response.statusCode === 404) { | ||
throw new Meteor.Error('federation-peer-does-not-exist', 'Peer does not exist'); | ||
} | ||
} | ||
|
||
// Check if we need to skip due to specific error | ||
if (skipRetryOnSpecificError(err)) { | ||
this.log('Retry: skipping due to specific error'); | ||
|
||
throw err; | ||
} | ||
|
||
if (i === retryInfo.total - 1) { | ||
// Throw the error, as we could not fulfill the request | ||
this.log('Retry: could not fulfill the request'); | ||
|
||
throw err; | ||
} | ||
|
||
const timeToRetry = retryInfo.stepSize * (i + 1) * retryInfo.stepMultiplier; | ||
|
||
this.log(`Trying again in ${ timeToRetry / 1000 }s: ${ method } - ${ uri }`); | ||
|
||
// Otherwise, wait and try again | ||
delay(timeToRetry); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { PeerHTTP } from './PeerHTTP'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
|
||
// Should skip the retry if the error is one of the below? | ||
const errorsToSkipRetrying = [ | ||
'error-app-prevented-sending', | ||
]; | ||
|
||
export function skipRetryOnSpecificError(err) { | ||
err = err && err.response && err.response.data; | ||
return errorsToSkipRetrying.includes(err && err.errorType); | ||
} | ||
|
||
// Delay method to wait a little bit before retrying | ||
export const delay = Meteor.wrapAsync(function(ms, callback) { | ||
Meteor.setTimeout(function() { | ||
callback(null); | ||
}, ms); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
app/federation/server/peerServer/index.js → app/federation/server/PeerServer/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import peerServer from './peerServer'; | ||
|
||
// Setup routes | ||
import './routes/events'; | ||
import './routes/uploads'; | ||
import './routes/users'; | ||
|
||
export default peerServer; | ||
export { PeerServer } from './PeerServer'; |
Oops, something went wrong.