Skip to content

Commit

Permalink
fix typos & hook up start/stop file upload functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Geo25rey committed Apr 2, 2024
1 parent 7bd6c54 commit 3b71b2a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ async function startup(): Promise<void> {

const api = new ApiModule(1337, core)
await api.listen()


const cleanup = async (code: number) => {
await core.stop()
await coreNew.stop()
await api.stop()
};

process.on("SIGINT", () => cleanup(0));
process.on("SIGTERM", () => cleanup(0));
process.on("beforeExit", cleanup);
}

void startup()
Expand Down
10 changes: 8 additions & 2 deletions src/modules/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { Module } from '@nestjs/common'
import { INestApplication, Module } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import { createSchema, createYoga } from 'graphql-yoga'
import { IPFSHTTPClient } from 'kubo-rpc-client'
Expand All @@ -24,6 +24,7 @@ class ControllerModule {}
* see api requirements here https://github.com/3speaknetwork/research/discussions/3
*/
export class ApiModule {
app: INestApplication
constructor(
private readonly listenPort: number,
private readonly self: CoreService
Expand All @@ -32,7 +33,8 @@ export class ApiModule {
}

public async listen() {
const app = await NestFactory.create(ControllerModule)
this.app = await NestFactory.create(ControllerModule)
const app = this.app

// Bring back API docs when needed. Mostly use already documented graphql
// const swaggerconfig = new DocumentBuilder().setTitle('VSC API').build()
Expand Down Expand Up @@ -78,4 +80,8 @@ export class ApiModule {

await app.listen(this.listenPort)
}

async stop() {
await this.app.close()
}
}
2 changes: 1 addition & 1 deletion src/services/new/contractEngineV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class ContractEngineV2 {
try {
const cid = CID.parse(json.codeStorageProof.hash)
const {value: msg} = await this.self.ipfs.dag.get(cid)
if (typeof msg?.cid !== 'string' || msg?.type !== 'data-availablity') {
if (typeof msg?.cid !== 'string' || msg?.type !== 'data-availability') {
continue;
}
if (msg.cid !== json.code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function ignoreMessagesFromSelf(
}
}

export class FileUploadManger {
export class FileUploadManager {
constructor(private core: NewCoreService) {}

async start() {
Expand Down Expand Up @@ -182,7 +182,7 @@ export class FileUploadManger {
if (cid.equals(request.cid)) {
// start BLS signing to generate a signature
const sigCid = await ipfs.dag.put({
type: 'data-availablity',
type: 'data-availability',
cid: cid.toString(),
})
await ipfs.pin.add(sigCid, { recursive: false })
Expand Down Expand Up @@ -279,7 +279,7 @@ export class FileUploadManger {
const sig = circuit.serialize(bls.circuit.circuitMap)
const data = await ipfs.dag.put(
{
type: 'data-availablity',
type: 'data-availability',
cid: respInfo.cid,
},
{ onlyHash: true },
Expand All @@ -302,4 +302,11 @@ export class FileUploadManger {
),
)
}

async stop() {
const { ipfs, config } = this.core
await ipfs.pubsub.unsubscribe(`${config.get('network.id')}-${REQUEST_TOPIC}`)
await ipfs.pubsub.unsubscribe(`${config.get('network.id')}-${REQUEST_DATA_TOPIC}`)
await ipfs.pubsub.unsubscribe(`${config.get('network.id')}-${RESPONSE_TOPIC}`)
}
}
6 changes: 5 additions & 1 deletion src/services/new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AddrRecord } from './types';
import { ContractEngineV2 } from './contractEngineV2';
import { VersionManager } from './witness/versionManager';
import { ElectionManager } from './witness/electionManager';
import { FileUploadManager } from './fileUploadManager';


export class NewCoreService {
Expand All @@ -38,6 +39,7 @@ export class NewCoreService {
miscDb: Collection;
versionManager: VersionManager
electionManager: ElectionManager
fileUploadManager: FileUploadManager;
nonceMap: Collection;

constructor() {
Expand All @@ -59,6 +61,7 @@ export class NewCoreService {
this.contractEngine = new ContractEngineV2(this)
this.versionManager = new VersionManager(this)
this.electionManager = new ElectionManager(this)
this.fileUploadManager = new FileUploadManager(this)
}

async init(oldService) {
Expand Down Expand Up @@ -93,9 +96,10 @@ export class NewCoreService {
await this.nodeIdentity.start()
await this.witness.start()
await this.electionManager.start()
await this.fileUploadManager.start()
}

async stop() {

await this.fileUploadManager.stop()
}
}

0 comments on commit 3b71b2a

Please sign in to comment.