diff --git a/app/modules/bma/lib/dtos.ts b/app/modules/bma/lib/dtos.ts index 1ba54fe4ad868ed08f51831de5fe06adcaaef113..dcf1ebe25054d7ee257ea4db8d6f367b63e66115 100644 --- a/app/modules/bma/lib/dtos.ts +++ b/app/modules/bma/lib/dtos.ts @@ -629,6 +629,11 @@ export const RequirementsPendingMembership = { type: String, blockstamp: String, sig: String, + signature: String, + issuer: String, + membership: String, + userid: String, + certts: String, }; export interface HttpRequirementsPendingMembership { diff --git a/app/modules/crawler/index.ts b/app/modules/crawler/index.ts index 77a3f2d7b9af186fbc024b78a100210732e9fb1a..bb3d869906e698d07bdc67de8fe72b62aa3da7ad 100644 --- a/app/modules/crawler/index.ts +++ b/app/modules/crawler/index.ts @@ -560,7 +560,8 @@ export const CrawlerDependency = { }, }, { - name: "import-lookup [search] [fromhost] [fromport] [tohost] [toport]", + name: + "import-lookup [search] [fromhost] [fromport] [frompath] [tohost] [toport] [topath]", desc: "Exchange peerings with another node", onDatabaseExecute: async ( server: Server, @@ -571,18 +572,31 @@ export const CrawlerDependency = { const search = params[0]; const fromhost = params[1]; const fromport = params[2]; - const tohost = params[3]; - const toport = params[4]; + const frompath = params[3]; + const tohost = params[4]; + const toport = params[5]; + const topath = params[6]; const logger = server.logger; try { logger.info( - 'Looking for "%s" at %s:%s...', + 'Looking for "%s" at %s:%s%s...', search, fromhost, - fromport + fromport, + frompath + ); + const sourcePeer = Contacter.fromHostPortPath( + fromhost, + fromport, + frompath, + { timeout: 60 * 1000 } + ); + const targetPeer = Contacter.fromHostPortPath( + tohost, + toport, + topath, + { timeout: 60 * 1000 } ); - const sourcePeer = new Contacter(fromhost, fromport); - const targetPeer = new Contacter(tohost, toport); const lookup = await sourcePeer.getLookup(search); for (const res of lookup.results) { for (const uid of res.uids) { @@ -626,7 +640,12 @@ export const CrawlerDependency = { } } } - const certBy = await sourcePeer.getCertifiedBy(search); + let certBy: any = { certifications: [] }; + try { + certBy = await sourcePeer.getCertifiedBy(search); + } catch (e) { + logger.error("No certified-by on remote"); + } const mapBlocks: any = {}; for (const signed of certBy.certifications) { if (signed.written) { @@ -666,7 +685,7 @@ export const CrawlerDependency = { }); try { logger.info( - "Success cert %s -> %s", + "Posting cert %s -> %s", certBy.pubkey.slice(0, 8), signed.uid ); @@ -676,6 +695,27 @@ export const CrawlerDependency = { } } } + // Memberships + const requirements = await sourcePeer.getRequirements(search); + for (let idty of requirements.identities) { + for (let pendingMs of idty.pendingMemberships) { + const rawMs = rawer.getMembership({ + currency: "g1", + issuer: pendingMs.issuer, + type: pendingMs.membership, + blockstamp: pendingMs.blockstamp, + userid: pendingMs.userid, + certts: pendingMs.certts, + signature: pendingMs.signature, + }); + try { + logger.info("Posting membership"); + await targetPeer.postRenew(rawMs); + } catch (e) { + logger.error(e); + } + } + } logger.info("Sent."); await server.disconnect(); } catch (e) {