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

Kad Import #2

Merged
merged 3 commits into from
Sep 28, 2023
Merged

Kad Import #2

merged 3 commits into from
Sep 28, 2023

Conversation

guillaumemichel
Copy link
Contributor

See probe-lab/go-kademlia#120 (comment) for reference.

Importing basic Kademlia types, as well as the trie, key and triert packages.

@dennis-tra
Copy link
Contributor

dennis-tra commented Sep 21, 2023

Awesome, thanks @guillaumemichel! This is how I thought the first step could look like. Love the go.mod with just a single test dependency. Let's see how long it'll stay that lean.

Some comments:

  • I'd prefer a shallow package hierarchy where the different key types would just live in a single directory, i.e., lift everything from bistrkey, key256, and key/test into the key package/folder. BitStrKey would then become only BitStr or BitString. Key256 would probably stay Key256 because the name cannot start with a number.
  • do we want to lift kadtest out of the internal package? We're using things from there in go-libp2p-kad-dht - for example the CtxShort. Probably more @iand might have a better overview?
  • Would be great to pull in UCI for automated tests (can be a separate PR)
  • There are a couple of interfaces in kad that we don't use anymore afaict. For example, Address and both <X>Protocol interfaces.

kad/key/key256/key256_test.go Outdated Show resolved Hide resolved
kad/key/key256/key256_test.go Outdated Show resolved Hide resolved
kad/key/key256/key256_test.go Outdated Show resolved Hide resolved
kad/key/key256/key256_test.go Outdated Show resolved Hide resolved
kad/key/key256/key256_test.go Outdated Show resolved Hide resolved
kad/key/key256/key256_test.go Outdated Show resolved Hide resolved
kad/kad.go Outdated
Comment on lines 136 to 144
type RoutingProtocol[K Key[K], N NodeID[K], A Address[A]] interface {
FindNode(ctx context.Context, to N, target K) (NodeInfo[K, A], []N, error)
Ping(ctx context.Context, to N) error
}

type RecordProtocol[K Key[K], N NodeID[K]] interface {
Get(ctx context.Context, to N, target K) ([]Record, []N, error)
Put(ctx context.Context, to N, record Record) error
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@iand I guess we went away from this pattern?

Co-authored-by: Dennis Trautwein <[email protected]>
@guillaumemichel
Copy link
Contributor Author

I'd prefer a shallow package hierarchy where the different key types would just live in a single directory, i.e., lift everything from bistrkey, key256, and key/test into the key package/folder. BitStrKey would then become only BitStr or BitString. Key256 would probably stay Key256 because the name cannot start with a number.

What are the benefits of a shallow package hierarchy?

The benefit I see for the current hierarchy are that users can choose to import only one type of Key and they don't end up importing a large package with many Keys they don't use. I am not against having all implementations in a key package, but would like to understand the benefits.

Would be great to pull in UCI for automated tests (can be a separate PR)

What is the process to pull these?

There are a couple of interfaces in kad that we don't use anymore afaict. For example, Address and both Protocol interfaces.

In this case I suggest to remove the following types:

  • NodeInfo
  • Address
  • Message
  • Request
  • Response
  • RoutingProtocol
  • RecordProtocol
  • Record

We can implement the necessary types in go-libp2p-kad-dht/v2 and move back some types here once we are happy with them if required.

@iand
Copy link
Contributor

iand commented Sep 27, 2023

My preference is also for shallower package hierarchies. But I think having a package for distinct types of key makes sense. I see an analogy with the crypto or hash package hierarches in the Go standard lib

However the current types names are awkward to work with and leads to stuttering:

  • bitstrkey.BitStrKey
  • key256.Key256

I would prefer:

  • bitstr.Key

key256 is hard to rename but perhaps this would be nicer

  • bit256.Key

Copy link
Contributor

@iand iand left a comment

Choose a reason for hiding this comment

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

Approved but I would like to see the naming of the key packages and types improved as per my comment

@guillaumemichel
Copy link
Contributor Author

Recent changes:

  • kadtest package lifted out of internal
  • moved bitstrkey.BitStrKey to bitstr.Key
  • moved key256.Key256 to bit256.Key
  • removed the following unused types:
    • NodeInfo
    • Address
    • Message
    • Request
    • Response
    • RoutingProtocol
    • RecordProtocol
    • Record

WDYT @dennis-tra

@dennis-tra
Copy link
Contributor

Hmm I'd still prefer a single key package :D the crypto packages are more sophisticated than what we're doing with our keys but it seems I'm outvoted :)

Fine with me to merge 👍

@guillaumemichel guillaumemichel merged commit 796722c into main Sep 28, 2023
4 checks passed
@guillaumemichel guillaumemichel deleted the kad-import branch September 28, 2023 11:27
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