Beispiel #1
0
        public static UplinkRequest Decode(G2Header root)
        {
            UplinkRequest request = new UplinkRequest();
            G2Header      child   = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                {
                    continue;
                }

                switch (child.Name)
                {
                case Packet_ProjectID:
                    request.ProjectID = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_LinkVersion:
                    request.LinkVersion = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_TargetVersion:
                    request.TargetVersion = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                    break;

                case Packet_Key:
                    request.Key   = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    request.KeyID = Utilities.KeytoID(request.Key);
                    break;

                case Packet_Target:
                    request.Target   = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                    request.TargetID = Utilities.KeytoID(request.Target);
                    break;
                }
            }

            return(request);
        }
Beispiel #2
0
        private void Process_UplinkReq(DataReq data, SignedData signed, UplinkRequest request)
        {
            Core.IndexKey(request.KeyID, ref request.Key);
            Core.IndexKey(request.TargetID, ref request.Target);

            if (!Utilities.CheckSignedData(request.Key, signed.Data, signed.Signature))
                return;

            OpTrust requesterTrust = GetTrust(request.KeyID);

            if (requesterTrust != null && requesterTrust.Loaded && requesterTrust.File.Header.Version > request.LinkVersion)
                return;

            // check if target in linkmap, if not add
            OpTrust targetTrust = GetTrust(request.TargetID);

            if (targetTrust == null)
            {
                targetTrust = new OpTrust(new OpVersionedFile(request.Target) );
                TrustMap.SafeAdd(request.TargetID, targetTrust);
            }

            if (targetTrust.Loaded && targetTrust.File.Header.Version > request.TargetVersion)
                return;

            request.Signed = signed.Encode(Network.Protocol); // so we can send it in results / save, later on

            // check for duplicate requests
            OpLink targetLink = targetTrust.GetLink(request.ProjectID);

            if (targetLink != null)
            {
                foreach (UplinkRequest compare in targetLink.Requests)
                    if (Utilities.MemCompare(compare.Signed, request.Signed))
                        return;
            }
            else
            {
                targetTrust.AddProject(request.ProjectID, true);
                targetLink = targetTrust.GetLink(request.ProjectID);
            }

            // add
            targetLink.Requests.Add(request);

            // if target is marked as linked or focused, update link of target and sender
            if (targetTrust.Loaded && (targetTrust.InLocalLinkTree || Core.KeepData.SafeContainsKey(targetTrust.UserID)))
            {
                if (targetTrust.File.Header.Version < request.TargetVersion)
                    Cache.Research(targetTrust.UserID);

                if (requesterTrust == null)
                {
                    requesterTrust = new OpTrust(new OpVersionedFile(request.Key));
                    TrustMap.SafeAdd(request.KeyID, requesterTrust);
                }

                // once new version of requester's link file has been downloaded, interface will be updated
                if (!requesterTrust.Loaded || (requesterTrust.File.Header.Version < request.LinkVersion))
                    Cache.Research(requesterTrust.UserID);
            }

            RunSaveUplinks = true;
        }
Beispiel #3
0
        private void LinkupRequest(OpLink remoteLink)
        {
            // create uplink request, publish
            UplinkRequest request = new UplinkRequest();
            request.ProjectID = remoteLink.Project;
            request.LinkVersion = LocalTrust.File.Header.Version;
            request.TargetVersion = remoteLink.Trust.File.Header.Version;
            request.Key = LocalTrust.File.Key;
            request.KeyID = LocalTrust.UserID;
            request.Target = remoteLink.Trust.File.Key;
            request.TargetID = remoteLink.UserID;

            byte[] signed = SignedData.Encode(Network.Protocol, Core.User.Settings.KeyPair, request);

            if(Network.Established)
                Store.PublishNetwork(request.TargetID, ServiceID, DataTypeFile, signed);

            // store locally
            Process_UplinkReq(null, new SignedData(Network.Protocol, Core.User.Settings.KeyPair, request), request);

            // publish at neighbors so they are aware of request status
            List<LocationData> locations = new List<LocationData>();
            GetLocs(Core.UserID, remoteLink.Project, 1, 1, locations);
            GetLocsBelow(Core.UserID, remoteLink.Project, locations);
            Store.PublishDirect(locations, request.TargetID, ServiceID, DataTypeFile, signed);
        }
Beispiel #4
0
        public static UplinkRequest Decode(G2Header root)
        {
            UplinkRequest request = new UplinkRequest();
            G2Header child = new G2Header(root.Data);

            while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD)
            {
                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_ProjectID:
                        request.ProjectID = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_LinkVersion:
                        request.LinkVersion = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_TargetVersion:
                        request.TargetVersion = BitConverter.ToUInt32(child.Data, child.PayloadPos);
                        break;

                    case Packet_Key:
                        request.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        request.KeyID = Utilities.KeytoID(request.Key);
                        break;

                    case Packet_Target:
                        request.Target = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        request.TargetID = Utilities.KeytoID(request.Target);
                        break;
                }
            }

            return request;
        }