Ejemplo n.º 1
0
        private async Task <string> GetRootHashAsyncUnderLock()
        {
            var tryReadResult = await objectStore.TryReadAsync(TreeNamespace, "root").ConfigureAwait(false);

            var rootExists = tryReadResult.Item1;

            return(rootExists
            ? CampfireNetHash.ConvertBase64BufferToSha256Base64String(tryReadResult.Item2)
            : null);
        }
Ejemplo n.º 2
0
        public static async Task <Tuple <bool, string> > TryWriteMerkleNodeAsync(this ICampfireNetObjectStore store, string ns, MerkleNode node)
        {
            using (var ms = new MemoryStream()) {
                using (var writer = new BinaryWriter(ms, Encoding.UTF8, true)) {
                    writer.WriteMerkleNode(node);
                }

                var objectData     = ms.GetBuffer();
                var length         = (int)ms.Position;
                var hash           = CampfireNetHash.ComputeSha256Base64(objectData, 0, length);
                var isNewlyWritten = await store.TryWriteUniqueAsync(ns, hash, objectData).ConfigureAwait(false);

//            var copy = await ReadMerkleNodeAsync(store, ns, hash).ConfigureAwait(false);
//            if (copy.TypeTag != node.TypeTag || copy.LeftHash != node.LeftHash || copy.RightHash != node.RightHash || copy.Descendents != node.Descendents) {
//               throw new InvalidStateException();
//            }
                return(Tuple.Create(isNewlyWritten, hash));
            }
        }