Skip to content
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

Merged
merged 7 commits into from
May 1, 2024
Merged

Conversation

wemeetagain
Copy link
Member

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 on self:peer:update events
  • disableIdentifyPush - set to true to disable identify-push entirely, this protocol isn't registered and identify-push messages can't be sent

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@wemeetagain wemeetagain requested a review from a team as a code owner February 1, 2024 22:42
@achingbrain
Copy link
Member

achingbrain commented Feb 2, 2024

Could these options be consolidated?

It would avoid the situation where a user sets both runOnSelfUpdate and disableIdentifyPush to true and expects something to happen.

Also, can you add some tests to ensure there are no regressions?

@wemeetagain
Copy link
Member Author

IMO they are two separate features.
One stops the outbound messages that automatically happen (but still allows manual outbound messages and allows handling inbound messages).
One stops the handling of inbound messages.

could we split the identify module into two? Then we wouldn't need the disable feature.
like:

createLibp2p({
  services: {
    identify: identify({...}),
    identifyPush: identifyPush({...}),
  }
})

@achingbrain
Copy link
Member

could we split the identify module into two?

This sounds like a good solution since it's a separate protocol, it could be exported from @libp2p/identify for convenience though since most people would want both most of the time.

BREAKING CHANGE:
identifyPush functionality has been removed from the identify module. In
order to get this functionality, the identifyPush module must be
instantiated separately.
@wemeetagain wemeetagain changed the title feat: allow disabling of identify-push feat!: split identify and identify-push Feb 5, 2024
Copy link
Member

@SgtPooki SgtPooki left a 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

Comment on lines 107 to 116
export interface IdentifyPushComponents {
peerId: PeerId
peerStore: PeerStore
connectionManager: ConnectionManager
registrar: Registrar
addressManager: AddressManager
events: TypedEventTarget<Libp2pEvents>
logger: ComponentLogger
nodeInfo: NodeInfo
}
Copy link
Member

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?

Suggested change
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
}

Comment on lines 73 to 76
/**
* How long we should wait for a remote peer to send their identify response
*/
timeout?: number
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -371,6 +252,180 @@ export class Identify implements Startable, IdentifyInterface {
stream.abort(err)
}
}
}

export class IdentifyPush implements Startable, IdentifyPushInterface {
Copy link
Member

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)?

Copy link
Member

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,
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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> {
Copy link
Member

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?

Comment on lines 278 to 299
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)
}
Copy link
Member

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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@achingbrain achingbrain merged commit 9d13a2f into main May 1, 2024
22 checks passed
@achingbrain achingbrain deleted the feat/no-auto-id-push branch May 1, 2024 11:14
@achingbrain achingbrain mentioned this pull request May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants