示例#1
0
        private void Process_PostHeader(DataReq data, SignedData signed, PostHeader header)
        {
            Core.IndexKey(header.SourceID, ref header.Source);
            Core.IndexKey(header.TargetID, ref header.Target);

            PostUID uid = new PostUID(header);

            OpPost current = GetPost(header.TargetID, uid);

            // if link loaded
            if (current != null)
            {
                // lower version, send update
                if (header.Version < current.Header.Version)
                {
                    if (data != null && data.Source != null)
                        Store.Send_StoreReq(data.Source, data.LocalProxy, new DataReq(null, header.TargetID, ServiceID, 0, current.SignedHeader));

                    return;
                }

                // higher version
                else if (header.Version > current.Header.Version)
                {
                    CachePost(signed, header);
                }

                // equal version do nothing
            }

            // else load file, set new header after file loaded
            else
                CachePost(signed, header);
        }
示例#2
0
        private void PostSearch(ulong target, PostUID uid, ushort version)
        {
            if (Core.InvokeRequired)
            {
                Core.RunInCoreAsync(delegate() { PostSearch(target, uid, version); });
                return;
            }

            byte[] parameters = new byte[PostSearch_ParamsSize];
            parameters[0] = (byte)BoardSearch.Post;
            uid.ToBytes().CopyTo(parameters, 1);
            BitConverter.GetBytes(version).CopyTo(parameters, 17);

            DhtSearch search = Core.Network.Searches.Start(target, "Board:Post", ServiceID, 0, parameters, Search_FoundPost);

            if (search == null)
                return;

            search.TargetResults = 2;
        }
示例#3
0
        private void CachePost(SignedData signedHeader, PostHeader header)
        {
            if (Core.InvokeRequired)
                Debug.Assert(false);

            if (header.ParentID == 0 && header.SourceID != header.TargetID)
            {
                Network.UpdateLog("Board", "Post made to board other than source's");
                return;
            }

            if (!File.Exists(GetPostPath(header)))
            {
                DownloadPost(signedHeader, header);
                return;
            }

            // check if current version loaded
            OpPost post = GetPost(header);

            if (post != null && post.Header.Version >= header.Version )
            {
                UpdateGui(post);
                return;
            }

            // put into map
            OpBoard board = GetBoard(header.TargetID);

            if (board == null)
            {
                board = new OpBoard(header.Target);
                BoardMap.SafeAdd(header.TargetID, board);
            }

            PostUID uid = new PostUID(header);

            post = new OpPost();
            post.Header = header;
            post.SignedHeader = signedHeader.Encode(Network.Protocol);
            post.Ident = header.TargetID.GetHashCode() ^ uid.GetHashCode();
            post.Unique = Loading;

            // remove previous version of file, if its different
            OpPost prevPost = board.GetPost(uid);

            if (prevPost != null && GetPostPath(prevPost.Header) != GetPostPath(header))
                try { File.Delete(GetPostPath(prevPost.Header)); }
                catch { }

            board.Posts.SafeAdd(uid,  post);

            // update replies
            if (post.Header.ParentID == 0)
                board.UpdateReplies(post);
            else
            {
                PostUID parentUid = new PostUID(board.UserID, post.Header.ProjectID, post.Header.ParentID);
                OpPost parentPost = board.GetPost(parentUid);

                if (parentPost != null)
                {
                    board.UpdateReplies(parentPost);
                    UpdateGui(post);
                }
            }

            lock (SaveHeaders)
                if (!SaveHeaders.Contains(header.TargetID))
                    SaveHeaders.Add(header.TargetID);

            ushort replies = 0;
            if (SavedReplyCount.SafeTryGetValue(post.Ident, out replies))
            {
                post.Replies = replies;
                SavedReplyCount.SafeRemove(post.Ident);
            }

            UpdateGui(post);

            if (Core.NewsWorthy(header.TargetID, header.ProjectID, true))
                Core.MakeNews(ServiceIDs.Board, "Board updated by " + Core.GetName(header.SourceID), header.SourceID, 0, false);
        }
示例#4
0
        public OpPost GetPost(ulong target, PostUID uid)
        {
            OpBoard board = GetBoard(target);

            if (board == null)
                return null;

            return board.GetPost(uid);
        }
示例#5
0
        public static PostUID FromBytes(byte[] data, int offset)
        {
            PostUID uid = new PostUID();

            uid.SenderID = BitConverter.ToUInt64(data, offset + 0);
            uid.ProjectID = BitConverter.ToUInt32(data, offset + 8);
            uid.PostID = BitConverter.ToUInt32(data, offset + 12);

            return uid;
        }
示例#6
0
        public OpPost GetPost(PostUID uid)
        {
            OpPost post = null;

            Posts.SafeTryGetValue(uid, out post);

            return post;
        }