Skip to content

Commit

Permalink
Merge pull request #6 from oceanprotocol/runningOceanNode
Browse files Browse the repository at this point in the history
Running ocean node
  • Loading branch information
jamiehewitt15 authored Nov 4, 2024
2 parents 856598f + 829e263 commit bebdb6b
Show file tree
Hide file tree
Showing 9 changed files with 2,492 additions and 192 deletions.
1,667 changes: 1,493 additions & 174 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@chainsafe/libp2p-noise": "^16.0.0",
"@chainsafe/libp2p-yamux": "^7.0.1",
"@libp2p/bootstrap": "^11.0.6",
"@libp2p/circuit-relay-v2": "^2.1.1",
"@libp2p/crypto": "^4.1.5",
"@libp2p/dcutr": "^2.0.6",
"@libp2p/identify": "^3.0.6",
"@libp2p/kad-dht": "^13.1.2",
"@libp2p/mdns": "^11.0.6",
"@libp2p/peer-id-factory": "^4.2.4",
"@libp2p/ping": "^2.0.6",
"@libp2p/tcp": "^10.0.7",
"@libp2p/websockets": "^9.0.6",
"@multiformats/multiaddr": "^12.3.1",
"@oceanprotocol/lib": "^3.3.3",
"axios": "^1.7.7",
"chai": "^4.3.10",
Expand All @@ -82,9 +96,13 @@
"crypto-js": "^4.2.0",
"ethers": "^5.7.2",
"fs": "^0.0.1-security",
"ip": "^2.0.1",
"it-pipe": "^3.0.1",
"libp2p": "^2.1.5",
"node-polyfill-webpack-plugin": "^4.0.0",
"os": "^0.1.2",
"path": "^0.12.7"
"path": "^0.12.7",
"private-ip": "^3.0.2"
},
"activationEvents": [
"onCommand:ocean-protocol.searchAssets",
Expand Down
60 changes: 60 additions & 0 deletions src/@types/monitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
export interface NodeIpAndDns {
ip: string
port: number
dns: string
relay: boolean
relayNode: string
}

export interface NodeLocation {
id: string
ip: string
country?: string
city?: string
lat?: number
lon?: number
}
export interface NodeCheckResult {
peerId: string
ipAddrs: NodeIpAndDns
success: boolean
errorCause: string
status: string
deltaTime: number
}

export interface NodeStatus {
id: string
location: NodeLocation
ipAndDns: NodeIpAndDns
eligible: boolean
eligibilityCauseStr: string
uptime: number
lastCheck: number
address: string
allowedAdmins: string[]
codeHash: string
http: boolean
p2p: boolean
indexer: any[]
platform: any
provider: any[]
publicKey: string
supportedStorage: any
version: string
}

export interface GeneralStatus {
id: number
week: number
totalUptime: number
lastRun: number
}

export interface NodeWeeklyUptime {
nodeId: string
week: number
address: string
uptime: number
lastCheck: number
}
93 changes: 93 additions & 0 deletions src/@types/p2p.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Stream } from 'stream'
export interface DenyList {
peers: string[]
ips: string[]
}

export interface OceanNodeKeys {
peerId: any
publicKey: any
privateKey: any
ethAddress: string
}
export interface P2PStatusResponse {
httpStatus: number
error?: string
headers?: any
}
export interface P2PCommandResponse {
status: P2PStatusResponse
stream: Stream | null
}

export interface OceanNodeP2PConfig {
bootstrapNodes: string[]
enableIPV4: boolean
enableIPV6: boolean
ipV4BindAddress: string | null
ipV4BindTcpPort: number | null
ipV4BindWsPort: number | null
ipV6BindAddress: string | null
ipV6BindTcpPort: number | null
ipV6BindWsPort: number | null
pubsubPeerDiscoveryInterval: number
dhtMaxInboundStreams: number
dhtMaxOutboundStreams: number
mDNSInterval: number
connectionsMaxParallelDials: number
connectionsDialTimeout: number
announceAddresses: string[]
filterAnnouncedAddresses: string[]
autoNat: boolean
upnp: boolean
enableCircuitRelayServer: boolean
enableCircuitRelayClient: boolean
circuitRelays: number
announcePrivateIp: boolean
minConnections: number
maxConnections: number
autoDialPeerRetryThreshold: number
autoDialConcurrency: number
maxPeerAddrsToDial: number
autoDialInterval: number
}

export interface OceanNodeProvider {
chainId: string
network: string
}

export interface OceanNodeIndexer {
chainId: string
network: string
block?: string // mark it as optional until the functionality is done
}
export interface StorageTypes {
ipfs: boolean
arwave: boolean
url: boolean
}

export interface OceanNodeStatus {
id: string
publicKey: string
address: string
version: string
http: boolean
p2p: boolean
provider: OceanNodeProvider[]
indexer: OceanNodeIndexer[]
supportedStorage: StorageTypes
platform: any
uptime?: number // seconds since start
codeHash?: string
allowedAdmins?: string[]
// detailed information
c2dClusters?: any
supportedSchemas?: any
}

export interface OceanNodeConfig {
keys: OceanNodeKeys
p2pConfig: OceanNodeP2PConfig | null
}
57 changes: 41 additions & 16 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@ import { ethers } from 'ethers'
import * as fs from 'fs'
import { createAsset } from './helpers/publish'
import fetch from 'cross-fetch'
import { OceanP2P } from './helpers/oceanNode'
import { download } from './helpers/download'

globalThis.fetch = fetch
const node = new OceanP2P()

export function activate(context: vscode.ExtensionContext) {
async function startOceanNode(): Promise<string> {
await node.start()
// sleep for 3 seconds
await new Promise((resolve) => setTimeout(resolve, 3000))

const thisNodeId = node._config.keys.peerId.toString()
console.log('Node ' + thisNodeId + ' started.')
vscode.window.showInformationMessage(`Ocean Node started with ID: ${thisNodeId}`)
return thisNodeId
}

export async function activate(context: vscode.ExtensionContext) {
console.log('Ocean Protocol extension is now active!')

const provider = new OceanProtocolViewProvider(context.extensionUri)
const nodeId = await startOceanNode()

const provider = new OceanProtocolViewProvider(context.extensionUri, nodeId)

context.subscriptions.push(
vscode.window.registerWebviewViewProvider(
Expand Down Expand Up @@ -95,17 +110,6 @@ export function activate(context: vscode.ExtensionContext) {

const signer = new ethers.Wallet(privateKey, provider)

// Test provider connectivity
try {
provider.network
} catch (networkError) {
console.error('Error connecting to network:', networkError)
vscode.window.showErrorMessage(
`Error connecting to network: ${networkError.message}`
)
return
}

const aquarius = new Aquarius(config.aquariusUrl)

const urlAssetId = await createAsset(
Expand Down Expand Up @@ -136,6 +140,29 @@ export function activate(context: vscode.ExtensionContext) {
}
)

let getOceanPeers = vscode.commands.registerCommand(
'ocean-protocol.getOceanPeers',
async () => {
try {
const peers = await node.getOceanPeers()
if (peers && peers.length > 0) {
vscode.window.showInformationMessage(`Ocean Peers:\n${peers.join('\n')}`)
} else {
vscode.window.showInformationMessage('No Ocean Peers found.')
}
} catch (error) {
console.error('Error getting Ocean Peers:', error)
if (error instanceof Error) {
vscode.window.showErrorMessage(`Error getting Ocean Peers: ${error.message}`)
} else {
vscode.window.showErrorMessage(
'An unknown error occurred while getting Ocean Peers.'
)
}
}
}
)

let downloadAsset = vscode.commands.registerCommand(
'ocean-protocol.downloadAsset',
async (config: any, filePath: string, privateKey: string, assetDid: string) => {
Expand Down Expand Up @@ -202,7 +229,5 @@ export function activate(context: vscode.ExtensionContext) {
}
)

context.subscriptions.push(getAssetDetails, publishAsset, downloadAsset)
context.subscriptions.push(getAssetDetails, publishAsset, downloadAsset, getOceanPeers)
}

export function deactivate() {}
28 changes: 28 additions & 0 deletions src/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const defaultBootstrapAddresses = [
'/ip4/212.146.66.248/tcp/30080/p2p/16Uiu2HAmTC7cW9fb5ooFUupm6sAkcRJHHLGhiq2Bor8CzAAwFJCo',
'/dns4/node1.oceanprotocol.com/tcp/9000/p2p/16Uiu2HAmLhRDqfufZiQnxvQs2XHhd6hwkLSPfjAQg1gH8wgRixiP',
// '/dns4/node1.oceanprotocol.com/tcp/9001/ws/p2p/16Uiu2HAmLhRDqfufZiQnxvQs2XHhd6hwkLSPfjAQg1gH8wgRixiP',
// '/dns6/node1.oceanprotocol.com/tcp/9002/p2p/16Uiu2HAmLhRDqfufZiQnxvQs2XHhd6hwkLSPfjAQg1gH8wgRixiP',
// '/dns6/node1.oceanprotocol.com/tcp/9003/ws/p2p/16Uiu2HAmLhRDqfufZiQnxvQs2XHhd6hwkLSPfjAQg1gH8wgRixiP',
// node 2
'/dns4/node2.oceanprotocol.com/tcp/9000/p2p/16Uiu2HAmHwzeVw7RpGopjZe6qNBJbzDDBdqtrSk7Gcx1emYsfgL4',
// '/dns4/node2.oceanprotocol.com/tcp/9001/ws/p2p/16Uiu2HAmHwzeVw7RpGopjZe6qNBJbzDDBdqtrSk7Gcx1emYsfgL4',
// '/dns6/node2.oceanprotocol.com/tcp/9002/p2p/16Uiu2HAmHwzeVw7RpGopjZe6qNBJbzDDBdqtrSk7Gcx1emYsfgL4',
// '/dns6/node2.oceanprotocol.com/tcp/9003/ws/p2p/16Uiu2HAmHwzeVw7RpGopjZe6qNBJbzDDBdqtrSk7Gcx1emYsfgL4',
// node 3
'/dns4/node3.oceanprotocol.com/tcp/9000/p2p/16Uiu2HAmBKSeEP3v4tYEPsZsZv9VELinyMCsrVTJW9BvQeFXx28U',
// '/dns4/node3.oceanprotocol.com/tcp/9001/ws/p2p/16Uiu2HAmBKSeEP3v4tYEPsZsZv9VELinyMCsrVTJW9BvQeFXx28U',
// '/dns6/node3.oceanprotocol.com/tcp/9002/p2p/16Uiu2HAmBKSeEP3v4tYEPsZsZv9VELinyMCsrVTJW9BvQeFXx28U',
// '/dns6/node3.oceanprotocol.com/tcp/9003/ws/p2p/16Uiu2HAmBKSeEP3v4tYEPsZsZv9VELinyMCsrVTJW9BvQeFXx28U',
// node 4
'/dns4/node4.oceanprotocol.com/tcp/9000/p2p/16Uiu2HAmSTVTArioKm2wVcyeASHYEsnx2ZNq467Z4GMDU4ErEPom'
// '/dns4/node4.oceanprotocol.com/tcp/9001/ws/p2p/16Uiu2HAmSTVTArioKm2wVcyeASHYEsnx2ZNq467Z4GMDU4ErEPom',
// '/dns6/node4.oceanprotocol.com/tcp/9002/p2p/16Uiu2HAmSTVTArioKm2wVcyeASHYEsnx2ZNq467Z4GMDU4ErEPom',
// '/dns6/node4.oceanprotocol.com/tcp/9003/ws/p2p/16Uiu2HAmSTVTArioKm2wVcyeASHYEsnx2ZNq467Z4GMDU4ErEPom'
]
export const OPFNodes = [
'https://node1.oceanprotocol.com:8000',
'https://node2.oceanprotocol.com:8000',
'https://node3.oceanprotocol.com:8000',
'https://node4.oceanprotocol.com:8000'
]
Loading

0 comments on commit bebdb6b

Please sign in to comment.