A pithy primer of Polykey
#777
Replies: 6 comments 15 replies
-
Beta Was this translation helpful? Give feedback.
-
|
This might function better as a discussion. Maybe I'll convert it. |
Beta Was this translation helpful? Give feedback.
-
|
Comments please @aryanjassal @brynblack. |
Beta Was this translation helpful? Give feedback.
-
I'm unable to understand how the |
Beta Was this translation helpful? Give feedback.
-
|
I've taken a look at the Kademlia paper and even asked ChatGPT to explain it to me, but I am struggling to grasp how the distance metric works in relation to a binary tree. In this image, the physical distance from Similarly, |
Beta Was this translation helpful? Give feedback.
-
|
The discovery domain requires a bit of improvement. It's supposed to act as a decentralized crawler. Lots of optimisation required here... as well as wasm based plugins to deal with various third party platforms. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Polykeyis a kind of a complex program. It is made up groups of functionality we calldomainsThese are a collection of classes, utilities and types, some are made up of a single class.For example, we have a domain called
keys. This handles the base level password, keys and certificate information that the rest ofPolykeymakes use of. It contains 2 main classes, theCertManagerand theKeyRing. What they each do is self explanatory and I'll leave it to you to dig deeper.Keep in mind that for the most part each of these classes are decorated with an
async-initgiving the class a life-cycle. So theKeyRingis aCreateDestroyStartStopstructure. Which just means that it has implemented aCreateKeyRingstatic factory function for creating the class. And contains astart,stopanddestroymethod. Any method insideKeyRingthat is decorated with@readycan only be called when theKeyRingis in the running state. Callingstopwill cause it to stop and active state and callingdestroywill clear any persistent state. That's all you really need to know for now. You will see this pattern everywhere inPolykeyand even other projects.Polykeycan be subdivided into a few aspects.keys,claimsandsigChaindomainsnodesand discovery domains.gestalts,sigchainandACLdomains.vaultsdomain.clientdomain.There are some others but those are the main ones. If you look into
Polykey/src/PolykeyAgent.ts
Line 244 in 2a88416
CreatePolykeyAgentmethod inside the maintry {} catchblock.Arguably the most important domain for
Polykeyas a product is thevaultsdomain. It's where all of the secret handling is and maybe one of the easier domains to read through. For that you'll want to start at theVaultManagerhttps://github.com/MatrixAI/Polykey/blob/staging/src/vaults/VaultManager.ts. Get a feel for that and the dig down intoVaultInternaland how that handles the data. Keep an eye out for thewithFpattern. You'll see that all over the place.After that the
nodesdomain is the next important. It handles all of the logic for managing connections in theNodeConnectionManager. Notably tracking data about other nodes in theNodeGraphand handling all of the logic for finding nodes you want to connect to and establishing that connection in theNodeManager. All of the connection related stuff is pretty complex so just skim over this. Dig into how theNodeConnectionManagerhttps://github.com/MatrixAI/Polykey/blob/staging/src/nodes/NodeConnectionManager.ts handles creating connections and how theNodeConnectionhttps://github.com/MatrixAI/Polykey/blob/staging/src/nodes/NodeConnection.ts wraps them. It uses an object map and locking to ensure that we don't create duplicateNodeConnections. Skim over whatNodeManagerhandles, especially the logic for finding nodes andNodeConnectionQueue, its pretty complex. Besides that, some good related reading is thekademliaspec https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf. Get an idea of howclosenessworks as a concept in Kademlia.Polykeyuses a lot of persistent state, this will be stored in theDBas encrypted data. So to get a good feel of what domains need data persistence just trace what depends on theDB. Along side this thekeysdomain maintains most of the information used for they cryptography functions. It stores the private and public keys. But also manages encryption keys for the DB and vaults domain.Polykeyneeds to track and maintain relationships and permissions between nodes. There are a few parts to this. One of the main ones areclaims. These in essences are a claim that are signed by one or more nodes. usually to state that two nodes own each other in a way that forms a gestalt. Other claims will be made and they can come later. These are stored in theSigChainwhich functions similar to a block chain where immutability of the chain is enforced by a claim including a hash of it's parent within it. So the history can't be modified without breaking the chain.The
ACLtracks permissions we give to other nodes. The main example of this is the permission to see and clone vaults from our node. It is a simple access control list that maps a permission to aNodeIDThe Gestalts domain manages keeping track of claims between nodes within a
gestalt. AGestaltis a graph formed of all nodes that hold claims between each other. So a collection of nodes can be considered a group of a whole. given how the structure works, you can't really reference a gestalt as a whole, you can only really reference it by a member or check if two nodes are part of a gestalt. TheGestaltGraphtracks our own gestalt but also other nodes gestalts. For the most part we only care about our own, or gestalts we have a first order relationship with via social or permission links.Following on from gestalts we have the
discoverydomain. This handles the logic for exploring and mapping these claims and links between nodes. It fills in theGestaltGraphwith this information and makes sure it's maintained.Have a read over this @aryanjassal @brynblack if you have any questions just ask them in the comments here. They'll be a great reference for later.
Beta Was this translation helpful? Give feedback.
All reactions