Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: update interfaces (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored Mar 24, 2022
1 parent d3a2c89 commit 2def2bd
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
},
"dependencies": {
"@libp2p/crypto": "^0.22.9",
"@libp2p/interfaces": "^1.3.14",
"@libp2p/interfaces": "^1.3.18",
"@libp2p/logger": "^1.1.2",
"@libp2p/peer-id": "^1.1.8",
"@libp2p/record": "^1.0.0",
Expand Down Expand Up @@ -172,9 +172,9 @@
"varint": "^6.0.0"
},
"devDependencies": {
"@libp2p/interface-compliance-tests": "^1.1.16",
"@libp2p/interface-compliance-tests": "^1.1.20",
"@libp2p/peer-id-factory": "^1.0.8",
"@libp2p/peer-store": "^1.0.6",
"@libp2p/peer-store": "^1.0.7",
"@types/lodash.random": "^3.2.6",
"@types/lodash.range": "^3.2.6",
"@types/node": "^16.11.26",
Expand Down
4 changes: 2 additions & 2 deletions src/content-routing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { QueryFunc } from '../query/types.js'
import type { CID } from 'multiformats/cid'
import type { AbortOptions } from '@libp2p/interfaces'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import { Components, Initializable } from '@libp2p/interfaces/components'

export interface ContentRoutingInit {
Expand Down Expand Up @@ -139,7 +139,7 @@ export class ContentRouting implements Initializable {

// yield values if we have some, also slice because maybe we got lucky and already have too many?
if (provs.length > 0) {
const providers: PeerData[] = []
const providers: PeerInfo[] = []

for (const peerId of provs.slice(0, toFind)) {
providers.push({
Expand Down
4 changes: 2 additions & 2 deletions src/kad-dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from './utils.js'
import { Logger, logger } from '@libp2p/logger'
import type { QueryOptions, Validators, Selectors, DHT } from '@libp2p/interfaces/dht'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import { CustomEvent, EventEmitter } from '@libp2p/interfaces'
import type { PeerId } from '@libp2p/interfaces/peer-id'
import type { CID } from 'multiformats/cid'
Expand Down Expand Up @@ -195,7 +195,7 @@ export class KadDHT extends EventEmitter<PeerDiscoveryEvents> implements DHT, In
this.querySelf.init(components)
}

async onPeerConnect (peerData: PeerData) {
async onPeerConnect (peerData: PeerInfo) {
this.log('peer %p connected', peerData.id)

if (this.lan) {
Expand Down
8 changes: 4 additions & 4 deletions src/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { peerIdFromBytes } from '@libp2p/peer-id'
import { Multiaddr } from '@multiformats/multiaddr'
import { Libp2pRecord } from '@libp2p/record'
import Proto from './dht.js'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'

export const MESSAGE_TYPE = Proto.Message.MessageType
export const CONNECTION_TYPE = Proto.Message.ConnectionType
Expand All @@ -23,8 +23,8 @@ export class Message {
public type: Proto.Message.MessageType
public key: Uint8Array
private clusterLevelRaw: number
public closerPeers: PeerData[]
public providerPeers: PeerData[]
public closerPeers: PeerInfo[]
public providerPeers: PeerInfo[]
public record?: Libp2pRecord

constructor (type: Proto.Message.MessageType, key: Uint8Array, level: number) {
Expand Down Expand Up @@ -88,7 +88,7 @@ export class Message {
}
}

function toPbPeer (peer: PeerData) {
function toPbPeer (peer: PeerInfo) {
const output: PBPeer = {
id: peer.id.toBytes(),
addrs: (peer.multiaddrs ?? []).map((m) => m.bytes),
Expand Down
4 changes: 2 additions & 2 deletions src/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { PeerId } from '@libp2p/interfaces/peer-id'
import type { AbortOptions, Startable } from '@libp2p/interfaces'
import type { Logger } from '@libp2p/logger'
import type { Duplex } from 'it-stream-types'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import { Components, Initializable } from '@libp2p/interfaces/components'

export interface NetworkInit {
Expand All @@ -25,7 +25,7 @@ export interface NetworkInit {
}

interface NetworkEvents {
'peer': CustomEvent<PeerData>
'peer': CustomEvent<PeerInfo>
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/peer-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PeerList {
}

/**
* Check if this PeerData is already in here
* Check if this PeerInfo is already in here
*/
has (peerId: PeerId) {
const match = this.list.find((i) => i.equals(peerId))
Expand Down
4 changes: 2 additions & 2 deletions src/peer-routing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { Network } from '../network.js'
import type { Logger } from '@libp2p/logger'
import type { AbortOptions } from '@libp2p/interfaces'
import type { QueryFunc } from '../query/types.js'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import type { PeerId } from '@libp2p/interfaces/peer-id'
import { Components, Initializable } from '@libp2p/interfaces/components'

Expand Down Expand Up @@ -296,7 +296,7 @@ export class PeerRouting implements Initializable {
async getCloserPeersOffline (key: Uint8Array, closerThan: PeerId) {
const id = await utils.convertBuffer(key)
const ids = this.routingTable.closestPeers(id)
const output: PeerData[] = []
const output: PeerInfo[] = []

for (const peerId of ids) {
if (peerId.equals(closerThan)) {
Expand Down
10 changes: 5 additions & 5 deletions src/query/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MESSAGE_TYPE_LOOKUP } from '../message/index.js'
import type { SendingQueryEvent, PeerResponseEvent, MessageType, DialingPeerEvent, AddingPeerEvent, ValueEvent, ProviderEvent, QueryErrorEvent, FinalPeerEvent } from '@libp2p/interfaces/dht'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import type { PeerId } from '@libp2p/interfaces/peer-id'
import type { Libp2pRecord } from '@libp2p/record'

Expand Down Expand Up @@ -32,8 +32,8 @@ export function sendingQueryEvent (fields: QueryEventFields): SendingQueryEvent
export interface PeerResponseEventField {
from: PeerId
messageType: MessageType
closer?: PeerData[]
providers?: PeerData[]
closer?: PeerInfo[]
providers?: PeerInfo[]
record?: Libp2pRecord
}

Expand All @@ -51,7 +51,7 @@ export function peerResponseEvent (fields: PeerResponseEventField): PeerResponse

export interface FinalPeerEventFields {
from: PeerId
peer: PeerData
peer: PeerInfo
}

export function finalPeerEvent (fields: FinalPeerEventFields): FinalPeerEvent {
Expand All @@ -77,7 +77,7 @@ export function queryErrorEvent (fields: ErrorEventFields): QueryErrorEvent {

export interface ProviderEventFields {
from: PeerId
providers: PeerData[]
providers: PeerInfo[]
}

export function providerEvent (fields: ProviderEventFields): ProviderEvent {
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/handlers/get-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { DHTMessageHandler } from '../index.js'
import type { Providers } from '../../providers.js'
import type { PeerRouting } from '../../peer-routing/index.js'
import type { PeerId } from '@libp2p/interfaces/peer-id'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import { Components, Initializable } from '@libp2p/interfaces/components'

const log = logger('libp2p:kad-dht:rpc:handlers:get-providers')
Expand Down Expand Up @@ -77,7 +77,7 @@ export class GetProvidersHandler implements DHTMessageHandler, Initializable {
}

async _getPeers (peerIds: PeerId[]) {
const output: PeerData[] = []
const output: PeerInfo[] = []
const addrFilter = this.lan ? removePublicAddresses : removePrivateAddresses

for (const peerId of peerIds) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import isPrivateIp from 'private-ip'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import { peerIdFromBytes } from '@libp2p/peer-id'
import type { PeerId } from '@libp2p/interfaces/peer-id'
import { RECORD_KEY_PREFIX } from './constants.js'

// const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
const PK_PREFIX = uint8ArrayFromString('/pk/')

export function removePrivateAddresses (peer: PeerData): PeerData {
export function removePrivateAddresses (peer: PeerInfo): PeerInfo {
return {
...peer,
multiaddrs: peer.multiaddrs.filter(multiaddr => {
Expand All @@ -29,7 +29,7 @@ export function removePrivateAddresses (peer: PeerData): PeerData {
}
}

export function removePublicAddresses (peer: PeerData): PeerData {
export function removePublicAddresses (peer: PeerInfo): PeerInfo {
return {
...peer,
multiaddrs: peer.multiaddrs.filter(multiaddr => {
Expand Down
6 changes: 3 additions & 3 deletions test/rpc/handlers/get-providers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { PeerRouting } from '../../../src/peer-routing/index.js'
import type { PeerId } from '@libp2p/interfaces/peer-id'
import { PersistentPeerStore } from '@libp2p/peer-store'
import { MemoryDatastore } from 'datastore-core'
import type { PeerData } from '@libp2p/interfaces/peer-data'
import type { PeerInfo } from '@libp2p/interfaces/peer-info'
import { Components } from '@libp2p/interfaces/components'

const T = MESSAGE_TYPE.GET_PROVIDERS
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('rpc - handlers - GetProviders', () => {
const v = values[0]
const msg = new Message(T, v.cid.bytes, 0)

const closer: PeerData[] = [{
const closer: PeerInfo[] = [{
id: closerPeer,
multiaddrs: [
new Multiaddr('/ip4/127.0.0.1/tcp/4002'),
Expand All @@ -74,7 +74,7 @@ describe('rpc - handlers - GetProviders', () => {
protocols: []
}]

const provider: PeerData[] = [{
const provider: PeerInfo[] = [{
id: providerPeer,
multiaddrs: [
new Multiaddr('/ip4/127.0.0.1/tcp/4002'),
Expand Down

0 comments on commit 2def2bd

Please sign in to comment.