aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2023-05-12 22:33:57 -0400
committerAnthony Wang2023-05-12 22:33:57 -0400
commit94f2b70dc7169ac90fdf7d23b823629f19ec7ea8 (patch)
tree48db186823d9eae3cb7bc5a9b048707470b6c445
parent70d158c6d107cbb29251985c34c503e53c8dd4e7 (diff)
Fix a few small things
-rw-r--r--README.md4
-rw-r--r--server/storage.go1
2 files changed, 3 insertions, 2 deletions
diff --git a/README.md b/README.md
index 5faa743..954211f 100644
--- a/README.md
+++ b/README.md
@@ -18,11 +18,11 @@ Alright, let's solve all those problems above with Kela! Kela consists of three
In Kela, each user has an ID, which is an Ed5519 public key encoded in URL-safe Base64. Each user is associated with one or more Kela servers, which store that user's data. To find out which servers a user is associated with, you can query the name resolution system, which acts as a configuration service for the storage and message services. All Kela servers participate in the name resolution system and act as DHT nodes. Each server stores a complete list of all DHT nodes. When a new server joins the DHT, it tries to peer with an existing server in the DHT. Say server `example.com` would like to peer with `test.net`. `example.com` first sends a GET request to `test.net/peer?peer=example.com`. `test.net` replies with its list of DHT nodes. Once `example.com` receives this reply, it adds `test.net` to its list of DHT nodes and attempts to peer with all servers in the reply that it hasn't peered with yet. `test.net` now also tries to peer with the server that just contacted it, in this case `example.com`. Servers periodically go through their list of DHT nodes and remove nodes that are no longer online.
-The DHT stores key-value pairs. The key consists of a user's public key and timestamp (the current Unix time in seconds divided by 600, rounded down). The value consists of a timestamp (the current Unix time in seconds), a list of servers that the user is associated with, where the first server is their primary server, and a signature. A key-value pair is assigned to the 5 servers with smallest SHA-256 hashes of their domain name greater than the SHA-256 hash of the key. The purpose of the elaborate timestamp in the key is to ensure that the set of servers assigned to a key-value pair rotates every 600 seconds so an attacker must control a very large portion of the DHT to do a denial-of-service attack against a specific key-value pair. When servers join and leave the DHT, the servers that a user is associated with will ensure that that user's key-value pair is assigned to a new server if necessary to ensure that 5 servers store that key-value pair. The DHT supports two operations, get and post. For post operations, the server checks the signature to ensure the validity of the request. When a server receives either of these two operations, it computes the SHA-256 hash of the key and checks if it is supposed to store that key-value pair or not. If it is supposed to store that key-value pair, it performs the operation on that pair. Otherwise, the server will contact in parallel the 5 servers that store this key-value pair. If the operation is a get, the server will look at the 5 replies and return the value with the most recent timestamp. If the operation is a post, and one of the 5 parallel requests fails, the server will remove that offline server from its DHT node list and assign a new server to this key-value pair to replace the offline one. Each server periodically goes through its stored key-value pairs and deletes old ones.
+The DHT stores key-value pairs. The key consists of a user's public key and timestamp (the current Unix time in seconds divided by 600, rounded down). The value consists of a timestamp (the current Unix time in seconds), a list of servers that the user is associated with, where the first server is their primary server, and a signature. A key-value pair is assigned to the 5 servers with smallest SHA-256 hashes of their domain name greater than the SHA-256 hash of the key. This allows the DHT to tolerate most of the servers failing, as long as 1 of the 5 servers is still online. The purpose of the elaborate timestamp in the key is to ensure that the set of servers assigned to a key-value pair rotates every 600 seconds so an attacker must control a very large portion of the DHT to do a denial-of-service attack against a specific key-value pair. When servers join and leave the DHT, the servers that a user is associated with will ensure that that user's key-value pair is assigned to a new server if necessary to ensure that 5 servers store that key-value pair. The DHT supports two operations, get and post. For post operations, the server checks the signature to ensure the validity of the request. When a server receives either of these two operations, it computes the SHA-256 hash of the key and checks if it is supposed to store that key-value pair or not. If it is supposed to store that key-value pair, it performs the operation on that pair. Otherwise, the server will contact in parallel the 5 servers that store this key-value pair. If the operation is a get, the server will look at the 5 replies and return the value with the most recent timestamp. If the operation is a post, and one of the 5 parallel requests fails, the server will remove that offline server from its DHT node list and assign a new server to this key-value pair to replace the offline one. Each server periodically goes through its stored key-value pairs and deletes old ones.
### Storage service
-The storage service uses a weaker form of primary-backup replication. The storage service supports the three operations get, post and delete, and a user's primary server always handles operations. Get operations are trivial. For a post or delete operation, the primary makes the modification and notifies all the backups about the operation, but responds to the user immediately without ensuring that the backups have performed the operation. All operations are stored in a log, which only stores the operation type and filename of the modified file, but not the contents of the operation. The log and files are persisted to disk. If a backup is offline, the primary maintains a log of all pending operations to be sent to the backup and will keep retrying. If the primary is offline, no progress can be made, but the user can designate any of the backups as the new primary, which also requires a post operation to the DHT to update that user's list of servers. When a backup becomes a primary, it must ensure that any other backups that are ahead of this one rollback their operations to match this backup. To rollback a post or delete operation, a backup can contact the new primary to get the file.
+The storage service uses a weaker form of primary-backup replication instead of a DHT for better performance. The storage service supports two operations get and post, and a user's primary server always handles operations. Get operations are directly read the file from disk. For a post operation, the primary makes the modification and notifies all the backups about the operation, but responds to the user immediately without ensuring that the backups have performed the operation. All operations are stored in a log, which only stores the filename of the modified file, but not the contents of the operation. The log and files are persisted to disk. If a backup is behind, the backup replies to operations with its current log length and the primary will send any missing log entries. If a backup is offline, the primary will keep retrying requests. If the primary is offline, no progress can be made, but the user can designate any of the backups as the new primary, which also requires a updating the user's list of servers in the DHT. When a backup becomes a primary, it must ensure that any other backups that are ahead of this one roll back their operations to match this backup. To roll back a post operation, a backup can contact the new primary to get a correct copy of the file.
### Message service
diff --git a/server/storage.go b/server/storage.go
index e845dd5..c05e29b 100644
--- a/server/storage.go
+++ b/server/storage.go
@@ -174,6 +174,7 @@ func storageHandler(w http.ResponseWriter, r *http.Request) {
return
}
}
+ user.log = user.log[:idx]
}
}