Ejemplo n.º 1
0
        internal static ShareCollection Decode(G2Header header, ulong user)
        {
            ShareCollection root = new ShareCollection(user);
            G2Header child = new G2Header(header.Data);

            while (G2Protocol.ReadNextChild(header, child) == G2ReadResult.PACKET_GOOD)
            {

                if (!G2Protocol.ReadPayload(child))
                    continue;

                switch (child.Name)
                {
                    case Packet_Hash:
                        root.Hash = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Size:
                        root.Size = CompactNum.ToInt64(child.Data, child.PayloadPos, child.PayloadSize);
                        break;

                    case Packet_Key:
                        root.Key = Utilities.ExtractBytes(child.Data, child.PayloadPos, child.PayloadSize);
                        break;
                }
            }

            return root;
        }
Ejemplo n.º 2
0
        internal void GetPublicList(ulong user)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(() => GetPublicList(user));
                return;
            }

            ShareCollection collection;
            if (!Collections.SafeTryGetValue(user, out collection))
            {
                collection = new ShareCollection(user);
                Collections.SafeAdd(user, collection);
            }

            AddTargets(collection.ToRequest, user, 0);

            foreach (DhtClient target in collection.ToRequest)
            {
                RudpSession session = Network.RudpControl.GetActiveSession(target);

                if (session == null)
                {
                    Network.RudpControl.Connect(target);
                    collection.Status = "Connecting to " + Core.GetName(target.UserID);
                }
                else
                    SendPublicRequest(session, collection);
            }
        }
Ejemplo n.º 3
0
        internal SharingService(OpCore core)
        {
            Core = core;
            Network = core.Network;

            string rootPath = Core.User.RootPath + Path.DirectorySeparatorChar +
                        "Data" + Path.DirectorySeparatorChar +
                        ServiceID.ToString() + Path.DirectorySeparatorChar;

            SharePath = rootPath + DataTypeShare.ToString() + Path.DirectorySeparatorChar;
            Directory.CreateDirectory(SharePath);

            PublicPath = rootPath + DataTypePublic.ToString() + Path.DirectorySeparatorChar;
            Directory.CreateDirectory(PublicPath);

            DownloadPath = Core.User.RootPath + Path.DirectorySeparatorChar + "Downloads" + Path.DirectorySeparatorChar;

            Core.SecondTimerEvent += new TimerHandler(Core_SecondTimer);
            Core.MinuteTimerEvent += new TimerHandler(Core_MinuteTimer);

            // data
            Network.RudpControl.SessionUpdate += new SessionUpdateHandler(Session_Update);
            Network.RudpControl.SessionData[ServiceID, DataTypeSession] += new SessionDataHandler(Session_Data);

            Core.Transfers.FileSearch[ServiceID, DataTypeShare] += new FileSearchHandler(Transfers_FileSearch);
            Core.Transfers.FileRequest[ServiceID, DataTypeShare] += new FileRequestHandler(Transfers_FileRequest);

            Core.Transfers.FileSearch[ServiceID, DataTypePublic] += new FileSearchHandler(Transfers_PublicSearch);
            Core.Transfers.FileRequest[ServiceID, DataTypePublic] += new FileRequestHandler(Transfers_PublicRequest);

            // location
            Network.Store.StoreEvent[ServiceID, DataTypeLocation] += new StoreHandler(Store_Locations);
            Network.Searches.SearchEvent[ServiceID, DataTypeLocation] += new SearchRequestHandler(Search_Locations);

            Local = new ShareCollection(Core.UserID);
            Collections.SafeAdd(Core.UserID, Local);

            LoadHeaders();
        }
Ejemplo n.º 4
0
        private void SendPublicRequest(RudpSession session, ShareCollection collection)
        {
            collection.Status = "Requesting List";

            session.SendData(ServiceID, DataTypeSession, new PublicShareRequest(), true);
        }
Ejemplo n.º 5
0
        private void ReceivePublicDetails(RudpSession session, ShareCollection file)
        {
            ShareCollection collection;
            if (!Collections.SafeTryGetValue(session.UserID, out collection))
                return;

            collection.Key = file.Key;
            collection.Size = file.Size;
            collection.Hash = file.Hash;

            foreach (DhtClient done in collection.ToRequest.Where(t => t.ClientID == session.ClientID).ToArray())
                collection.ToRequest.Remove(done);

            FileDetails details = new FileDetails(ServiceID, DataTypePublic, file.Hash, file.Size, null);
            object[] args = new object[] { collection, (object) session.ClientID };

            DhtClient client = new DhtClient(session.UserID, session.ClientID);
            OpTransfer transfer = Core.Transfers.StartDownload(client.UserID, details, args, new EndDownloadHandler(CollectionDownloadFinished));
            transfer.AddPeer(client);
            transfer.DoSearch = false;

            collection.Status = "Starting List Download";
        }
Ejemplo n.º 6
0
 private string GetPublicPath(ShareCollection collection)
 {
     return PublicPath + Utilities.CryptFilename(Core, collection.UserID, collection.Hash);
 }