-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: split identify and identify-push #2387
Conversation
Could these options be consolidated? It would avoid the situation where a user sets both Also, can you add some tests to ensure there are no regressions? |
IMO they are two separate features. could we split the identify module into two? Then we wouldn't need the disable feature. createLibp2p({
services: {
identify: identify({...}),
identifyPush: identifyPush({...}),
}
}) |
This sounds like a good solution since it's a separate protocol, it could be exported from |
BREAKING CHANGE: identifyPush functionality has been removed from the identify module. In order to get this functionality, the identifyPush module must be instantiated separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments. Not sure how closely related these are but since the original proposal was a config, I assume they're both largely the same under the hood, in which case a base class they both extend could make the code much more manage-able, and less likely to fork in breaking ways when fixing bugs
export interface IdentifyPushComponents { | ||
peerId: PeerId | ||
peerStore: PeerStore | ||
connectionManager: ConnectionManager | ||
registrar: Registrar | ||
addressManager: AddressManager | ||
events: TypedEventTarget<Libp2pEvents> | ||
logger: ComponentLogger | ||
nodeInfo: NodeInfo | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is IdentifyPush
expected to be a super-set of Identify
?
export interface IdentifyPushComponents { | |
peerId: PeerId | |
peerStore: PeerStore | |
connectionManager: ConnectionManager | |
registrar: Registrar | |
addressManager: AddressManager | |
events: TypedEventTarget<Libp2pEvents> | |
logger: ComponentLogger | |
nodeInfo: NodeInfo | |
} | |
export interface IdentifyPushComponents extends IdentifyComponents { | |
connectionManager: ConnectionManager | |
} |
/** | ||
* How long we should wait for a remote peer to send their identify response | ||
*/ | ||
timeout?: number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like an "identify-listen" capability. Does this belong in identifyPush? Maybe IdentifyPush needs a different name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identify/push is the name of the protocol - https://github.com/libp2p/specs/blob/master/identify/README.md#identifypush
@@ -371,6 +252,180 @@ export class Identify implements Startable, IdentifyInterface { | |||
stream.abort(err) | |||
} | |||
} | |||
} | |||
|
|||
export class IdentifyPush implements Startable, IdentifyPushInterface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a jsdoc explaining how this is different than identify? is this an extension of identify? can this be used in place of identify, or are both needed (and in what scenarios would they both be needed)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @packageDocumentation
block links to the spec which should answer these questions. If not it should be expanded - please suggest an edit.
maxObservedAddresses: 10, | ||
maxIdentifyMessageSize: 8192, | ||
runOnConnectionOpen: true, | ||
runOnSelfUpdate: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type doesn't exist on IdentifyInit
. Is that expected?
@@ -65,23 +59,60 @@ export interface IdentifyInit { | |||
runOnTransientConnection?: boolean | |||
} | |||
|
|||
export interface IdentifyPushInit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export interface IdentifyPushInit { | |
export interface IdentifyPushInit extends IdentifyInit { |
|
||
if (message.publicKey != null) { | ||
peer.publicKey = message.publicKey | ||
async function consumeIdentifyMessage (peerStore: PeerStore, events: TypedEventTarget<Libp2pEvents>, log: Logger, connection: Connection, message: IdentifyMessage): Promise<IdentifyResult> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this no longer private on purpose?
constructor (components: IdentifyPushComponents, init: IdentifyPushInit = {}) { | ||
this.started = false | ||
this.peerId = components.peerId | ||
this.peerStore = components.peerStore | ||
this.registrar = components.registrar | ||
this.addressManager = components.addressManager | ||
this.connectionManager = components.connectionManager | ||
this.events = components.events | ||
this.log = components.logger.forComponent('libp2p:identify:push') | ||
|
||
this.identifyPushProtocolStr = `/${init.protocolPrefix ?? defaultValues.protocolPrefix}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION}` | ||
this.timeout = init.timeout ?? defaultValues.timeout | ||
this.maxInboundStreams = init.maxInboundStreams ?? defaultValues.maxInboundStreams | ||
this.maxOutboundStreams = init.maxOutboundStreams ?? defaultValues.maxOutboundStreams | ||
this.maxIdentifyMessageSize = init.maxIdentifyMessageSize ?? defaultValues.maxIdentifyMessageSize | ||
this.runOnTransientConnection = init.runOnTransientConnection ?? defaultValues.runOnTransientConnection | ||
|
||
// Store self host metadata | ||
this.host = { | ||
protocolVersion: `${init.protocolPrefix ?? defaultValues.protocolPrefix}/${IDENTIFY_PROTOCOL_VERSION}`, | ||
agentVersion: getAgentVersion(components.nodeInfo, init.agentVersion) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to consolidate a lot of this into a base identify class that both extend from so they're more manageable.
} | ||
}) | ||
|
||
await this.registrar.handle(this.identifyPushProtocolStr, (data) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await this.registrar.handle(this.identifyPushProtocolStr, (data) => { | |
await this.registrar.handle(this.protocolStr, (data) => { |
could help if we were to consolidate logic into a base class
Description
Add two options to the identify module to disable various parts of identify-push
runOnSelfUpdate
- set to false to stop sending identify-push messages automatically onself:peer:update
eventsdisableIdentifyPush
- set to true to disable identify-push entirely, this protocol isn't registered and identify-push messages can't be sentChange checklist