@namespace("keybase.1")

protocol block {
  import idl "backend_common.avdl";

  record GetBlockRes {
    string blockKey;
    bytes buf;
  }

  // Fixed-size nonce to identify a reference to a block
  fixed BlockRefNonce(8);

  record BlockReference {
    BlockIdCombo bid;
    BlockRefNonce nonce;
    UID chargedTo;
  }

  record BlockReferenceCount{
    BlockReference ref;
    int liveCount;
  }

  record DowngradeReferenceRes{
    array<BlockReferenceCount> completed;
    BlockReference failed;
  }

  record BlockPingResponse {
    // In the future, we might want to respond with timestamps or
    // ping intervals.
  }


  ChallengeInfo getSessionChallenge();
  void authenticateSession(string signature);

  void putBlock(BlockIdCombo bid, string folder, string blockKey, bytes buf);
  GetBlockRes getBlock(BlockIdCombo bid, string folder);

  void addReference(string folder, BlockReference ref);
  void delReference(string folder, BlockReference ref);
  array<BlockReference> archiveReference(string folder, array<BlockReference> refs);

  DowngradeReferenceRes delReferenceWithCount(string folder, array<BlockReference> refs);
  DowngradeReferenceRes archiveReferenceWithCount(string folder, array<BlockReference> refs);

  bytes getUserQuotaInfo();

  BlockPingResponse blockPing();
}
