package peergos.shared.corenode;

import peergos.shared.crypto.hash.*;
import peergos.shared.social.*;

import java.io.*;
import java.util.*;
import java.util.concurrent.*;

public interface CoreNode {
    int MAX_USERNAME_SIZE = 64;
    int MAX_USERNAME_COUNT = 1024;

    /**
     *
     * @param username
     * @return the key chain proving the claim of the requested username
     */
    CompletableFuture<List<UserPublicKeyLink>> getChain(String username);

    /** Claim a username, or change the public key owning a username
     *
     * @param username
     * @param chain
     * @return
     */
    CompletableFuture<Boolean> updateChain(String username, List<UserPublicKeyLink> chain);

    /**
     *
     * @param key
     * @return the username claimed by a given public key
     */
    CompletableFuture<String> getUsername(PublicKeyHash key);

    /**
     *
     * @param prefix
     * @return All usernames starting with prefix
     */
    CompletableFuture<List<String>> getUsernames(String prefix);

    /**
     *
     * @param username
     * @return the public key for a username, if present
     */
    default CompletableFuture<Optional<PublicKeyHash>> getPublicKeyHash(String username) {
        return getChain(username).thenApply(chain -> {
            if (chain.size() == 0)
                return Optional.empty();
            else
                return Optional.of(chain.get(chain.size() - 1).owner);
        });
    }

    void close() throws IOException;
}

@@ -369,25 +369,63 @@
 ted username
+ and the ipfs node id of their storage
 %0A
-
      */%0A    
@@ -613,31 +613,91 @@
 am chain
-%0A     * @return
+ The changed links of the chain%0A     * @return True if successfully updated
 %0A     */
@@ -797,32 +797,32 @@
 %0A    /**%0A     *%0A
-
      * @param ke
@@ -818,24 +818,70 @@
 * @param key
+ the hash of the public identity key of a user
 %0A     * @ret

Improve corenode javadoc