Skip to content

Commit

Permalink
Merge branch 'main' into user-id-as-UInt8Array
Browse files Browse the repository at this point in the history
  • Loading branch information
teogeb committed Oct 24, 2024
2 parents 7940ee9 + 336f1fd commit 98ec7b0
Show file tree
Hide file tree
Showing 185 changed files with 892 additions and 4,940 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ Changes before Tatum release are not documented in this file.

#### Changed

- **BREAKING CHANGE:** Replace `--dev` flag with `--env` flag (https://github.com/streamr-dev/network/pull/2817)
- **BREAKING CHANGE:** Replace `--dev` flag with `--env` flag (https://github.com/streamr-dev/network/pull/2817, https://github.com/streamr-dev/network/pull/2834)
- the `--env` flag supports multiple environments
- it takes precedence over the options defined in a config file
- use `--env dev2` for the development environment

#### Deprecated
Expand Down
72 changes: 70 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/autocertifier-server/src/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class Database {
return ret
}

public async getAllSubdomains(): Promise<Array<Subdomain> | undefined> {
let ret: Array<Subdomain> | undefined
public async getAllSubdomains(): Promise<Subdomain[] | undefined> {
let ret: Subdomain[] | undefined
try {
ret = await this.getAllSubdomainsStatement!.all()
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions packages/autocertifier-server/src/RestServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const sendResponse = (res: express.Response, data?: object) => {

const parseIpAndPort = (req: express.Request): { ip: string, port: string } | undefined => {
// take x-forwarded for into account
const remoteIp = req.headers['x-forwarded-for'] || req.socket.remoteAddress
const remotePort = req.headers['x-forwarded-port'] || req.socket.remotePort
const remoteIp = req.headers['x-forwarded-for'] ?? req.socket.remoteAddress
const remotePort = req.headers['x-forwarded-port'] ?? req.socket.remotePort
let ip = remoteIp
let port = remotePort
if (typeof remoteIp !== 'string' && typeof remoteIp !== 'number') {
Expand Down
7 changes: 0 additions & 7 deletions packages/browser-test-runner/index.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/browser-test-runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"url": "git+https://github.com/streamr-dev/network.git",
"directory": "packages/browser-test-runner"
},
"main": "./index.js",
"main": "./dist/src/exports.js",
"scripts": {
"build": "tsc -b tsconfig.node.json",
"eslint": "eslint --cache --cache-location=node_modules/.cache/.eslintcache/ '**/*.{js,ts}'"
},
"author": "Streamr Network AG <contact@streamr.network>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const fs = require('fs')
import fs from 'fs'

const DEBUG_MODE = process.env.BROWSER_TEST_DEBUG_MODE ?? false

module.exports = function(testPaths, webpackConfig, localDirectory) {
export const createKarmaConfig = (
testPaths: string[], webpackConfig: () => Record<string, any>, localDirectory: string
): (config: any) => any => {
const setupFiles = [__dirname + '/karma-setup.js']
const localSetupFile = localDirectory + '/karma-setup.js'
if (fs.existsSync(localSetupFile)) {
setupFiles.push(localSetupFile)
}
const preprocessors = {}
const preprocessors: Record<string, string[]> = {}
setupFiles.forEach((f) => preprocessors[f] = ['webpack'])
testPaths.forEach((f) => preprocessors[f] = ['webpack', 'sourcemap'])
return (config) => {
return (config: any) => {
config.set({
plugins: [
'karma-electron',
Expand All @@ -38,18 +40,18 @@ module.exports = function(testPaths, webpackConfig, localDirectory) {
webSecurity: false,
sandbox: false
},
show: DEBUG_MODE // set to true to show the electron window
show: DEBUG_MODE // set to true to show the electron window
}
}
},
browserDisconnectTimeout: 60000,
browserNoActivityTimeout: 400000,
browsers: ['CustomElectron'],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
clearContext: false, // leave Jasmine Spec Runner output visible in browser
useIframe: false,
},
singleRun: !DEBUG_MODE, //set to false to leave electron window open
singleRun: !DEBUG_MODE, //set to false to leave electron window open
webpack: {
...webpackConfig(),
entry: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const path = require('path')
const webpack = require('webpack')
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
import path from 'path'
import webpack from 'webpack'
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin'

module.exports = function({ entry, libraryName, alias = {} }) {
export const createWebpackConfig = (
{ entry, libraryName, alias = {} }: { entry: string, libraryName: string, alias: Record<string, string> }
): Record<string, any> => {
return () => {
return {
cache: {
Expand All @@ -25,7 +27,7 @@ module.exports = function({ entry, libraryName, alias = {} }) {
},
plugins: [
new NodePolyfillPlugin({
includeAliases: [
additionalAliases: [
'constants',
'crypto',
'path',
Expand Down
2 changes: 2 additions & 0 deletions packages/browser-test-runner/src/exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { createKarmaConfig } from './createKarmaConfig'
export { createWebpackConfig } from './createWebpackConfig'
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions packages/browser-test-runner/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.node.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"src/**/*"
]
}
4 changes: 2 additions & 2 deletions packages/cdn-location/src/getLocalRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const getLocalAirportCode: () => Promise<string | undefined> = async () =
}

export const getLocalAirportCodeByCoordinates: (latitude: number, longitude: number) => string = (latitude, longitude) => {
const distances: Array<[airportCode: string, distance: number]> = []
const distances: [airportCode: string, distance: number][] = []

Object.keys(airportCodeToRegion).forEach((key) => {
const airport = airportCodeToRegion[key]
Expand Down Expand Up @@ -78,7 +78,7 @@ export const getLocalRegion: () => Promise<number> = async () => {
}

export const getLocalRegionByCoordinates: (latitude: number, longitude: number) => number = (latitude, longitude) => {
const distances: Array<[regionNumber: number, distance: number]> = []
const distances: [regionNumber: number, distance: number][] = []

Object.keys(airportCodeToRegion).forEach((key) => {
const airport = airportCodeToRegion[key]
Expand Down
81 changes: 81 additions & 0 deletions packages/cli-tools/bin/streamr-internal-node-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env node
import '../src/logLevel'

import { DhtNode, PeerDescriptor, toDhtAddress, toNodeId } from '@streamr/dht'
import StreamrClient, { DhtAddress } from '@streamr/sdk'
import { NetworkNode, NodeInfo, StreamPartitionInfo } from '@streamr/trackerless-network'
import { binaryToHex, ChangeFieldType, Logger } from '@streamr/utils'
import { createClientCommand } from '../src/command'
import semver from 'semver'

const logger = new Logger(module)

export type NormalizedNodeInfo = ChangeFieldType<
NodeInfo,
'streamPartitions',
Omit<StreamPartitionInfo, 'deprecatedContentDeliveryLayerNeighbors'>[]>

const toNormalizeNodeInfo = (info: NodeInfo): NormalizedNodeInfo => {
const isLegacyFormat = semver.satisfies(semver.coerce(info.version)!, '< 102.0.0')
return {
...info,
streamPartitions: info.streamPartitions.map((sp: StreamPartitionInfo) => ({
...sp,
contentDeliveryLayerNeighbors: !isLegacyFormat
? sp.contentDeliveryLayerNeighbors
: sp.deprecatedContentDeliveryLayerNeighbors.map((n) => ({
peerDescriptor: n
}))
}))
}
}

const createPeerDescriptorOutput = (peerDescriptor: PeerDescriptor) => {
return {
nodeId: toNodeId(peerDescriptor),
type: peerDescriptor.type,
udp: peerDescriptor.udp,
tcp: peerDescriptor.tcp,
websocket: peerDescriptor.websocket,
region: peerDescriptor.region,
ipAddress: peerDescriptor.ipAddress,
publicKey: (peerDescriptor.publicKey !== undefined) ? binaryToHex(peerDescriptor.publicKey) : undefined,
signature: (peerDescriptor.signature !== undefined) ? binaryToHex(peerDescriptor.signature) : undefined
}
}

const createNodeInfoOutput = (nodeInfo: NormalizedNodeInfo) => {
return {
peerDescriptor: createPeerDescriptorOutput(nodeInfo.peerDescriptor),
controlLayer: {
neighbors: nodeInfo.controlLayer.neighbors.map((n) => toNodeId(n)),
connections: nodeInfo.controlLayer.connections.map((n) => toNodeId(n))
},
streamPartitions: nodeInfo.streamPartitions.map((sp) => ({
id: sp.id,
controlLayerNeighbors: sp.controlLayerNeighbors.map((n) => toNodeId(n)),
contentDeliveryLayerNeighbors: sp.contentDeliveryLayerNeighbors.map((n) => ({
nodeId: toNodeId(n.peerDescriptor),
rtt: n.rtt
}))
})),
version: nodeInfo.version
}
}

createClientCommand(async (client: StreamrClient, nodeId: string) => {
const networkNode = await client.getNode().getNode() as NetworkNode
const controlLayerNode = networkNode.stack.getControlLayerNode()
const peerDescriptors = await (controlLayerNode as DhtNode).findClosestNodesFromDht(nodeId as DhtAddress)
const peerDescriptor = peerDescriptors.find((pd) => toDhtAddress(pd.nodeId) === nodeId)
if (peerDescriptor !== undefined) {
const info = await networkNode.stack.fetchNodeInfo(peerDescriptor)
const normalizedInfo = toNormalizeNodeInfo(info)
console.log(JSON.stringify(createNodeInfoOutput(normalizedInfo), undefined, 4))
} else {
logger.error('No peer descriptor found')
}
})
.description('show detailed information about a node')
.arguments('nodeId')
.parseAsync()
11 changes: 11 additions & 0 deletions packages/cli-tools/bin/streamr-internal-show-sdk-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node
import '../src/logLevel'

import StreamrClient from '@streamr/sdk'
import { createClientCommand } from '../src/command'

createClientCommand(async (client: StreamrClient) => {
const config = client.getConfig()
console.log(JSON.stringify(config, undefined, 4))
})
.parseAsync()
2 changes: 2 additions & 0 deletions packages/cli-tools/bin/streamr-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ program
.version(pkg.version)
.usage('<command> [<args>]')
.description('subcommands for internal use, the API of the commands may change')
.command('node-info', 'info about a node')
.command('visualize-topology', 'visualize network topology')
.command('show-sdk-config', 'show config used by internal StreamrClient')
.parse()
6 changes: 5 additions & 1 deletion packages/cli-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,23 @@
"author": "Streamr Network AG <contact@streamr.com>",
"license": "AGPL-3.0",
"dependencies": {
"@streamr/dht": "102.0.0-beta.0",
"@streamr/sdk": "102.0.0-beta.0",
"@streamr/trackerless-network": "102.0.0-beta.0",
"@streamr/utils": "102.0.0-beta.0",
"commander": "^12.1.0",
"easy-table": "^1.1.1",
"ethers": "^6.13.0",
"event-stream": "^4.0.1",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"semver": "^7.6.3"
},
"devDependencies": {
"@streamr/test-utils": "102.0.0-beta.0",
"@types/event-stream": "^4.0.5",
"@types/lodash": "^4.17.12",
"@types/merge2": "^1.4.4",
"@types/semver": "^7.5.8",
"merge2": "^1.4.1"
}
}
Loading

0 comments on commit 98ec7b0

Please sign in to comment.