diff --git a/app/modules/bma/lib/dtos.ts b/app/modules/bma/lib/dtos.ts index cb354c9ad45129c8860979d59361623aba012961..e236aa61186f3ede696ecd55c93cfc47f7d863a5 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 d6c26eb090c485b78014ddb7888af3c82c447878..839784542caa0cde7d24d06d85aa64ab0364fe22 100644 --- a/app/modules/crawler/index.ts +++ b/app/modules/crawler/index.ts @@ -561,7 +561,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, @@ -572,18 +573,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) { @@ -627,7 +641,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) { @@ -667,7 +686,7 @@ export const CrawlerDependency = { }); try { logger.info( - "Success cert %s -> %s", + "Posting cert %s -> %s", certBy.pubkey.slice(0, 8), signed.uid ); @@ -677,6 +696,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) {