Ejemplo n.º 1
0
        public void AddRouterInfo(I2PRouterInfo info)
        {
            if (!ValidateRI(info))
            {
                return;
            }

            lock ( RouterInfos )
            {
                if (RouterInfos.ContainsKey(info.Identity.IdentHash))
                {
                    var indb = RouterInfos[info.Identity.IdentHash];

                    if (((DateTime)info.PublishedDate - (DateTime)indb.Key.PublishedDate).TotalSeconds > 10)
                    {
                        if (!info.VerifySignature())
                        {
                            Logging.LogDebug($"NetDb: RouterInfo failed signature check: {info.Identity.IdentHash.Id32}");
                            return;
                        }

                        var meta = indb.Value;
                        meta.Deleted = false;
                        meta.Updated = true;
                        RouterInfos[info.Identity.IdentHash] = new KeyValuePair <I2PRouterInfo, RouterInfoMeta>(info, meta);
                        Logging.LogDebugData($"NetDb: Updated RouterInfo for: {info.Identity.IdentHash}");
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (!info.VerifySignature())
                    {
                        Logging.LogDebug("NetDb: RouterInfo failed signature check: " + info.Identity.IdentHash.Id32);
                        return;
                    }

                    var meta = new RouterInfoMeta
                    {
                        Updated = true
                    };
                    RouterInfos[info.Identity.IdentHash] = new KeyValuePair <I2PRouterInfo, RouterInfoMeta>(info, meta);
                    Logging.LogDebugData($"NetDb: Added RouterInfo for: {info.Identity.IdentHash}");
                }

                if (RouterInfoUpdates != null)
                {
                    ThreadPool.QueueUserWorkItem(a => RouterInfoUpdates(info));
                }
            }
        }
Ejemplo n.º 2
0
        public bool AddRouterInfo(I2PRouterInfo info)
        {
            if (!ValidateRI(info))
            {
                return(false);
            }

            if (RouterInfos.TryGetValue(info.Identity.IdentHash, out var indb))
            {
                if (((DateTime)info.PublishedDate - (DateTime)indb.Router.PublishedDate).TotalSeconds > 2)
                {
                    if (!info.VerifySignature())
                    {
                        Logging.LogDebug($"NetDb: RouterInfo failed signature check: {info.Identity.IdentHash.Id32}");
                        return(false);
                    }

                    var meta = indb.Meta;
                    meta.Deleted = false;
                    meta.Updated = true;
                    var re = new RouterEntry(info, meta);
                    RouterInfos[info.Identity.IdentHash] = re;
                    if (re.IsFloodfill)
                    {
                        FloodfillInfos[info.Identity.IdentHash] = re;
                    }
                    Logging.LogDebugData($"NetDb: Updated RouterInfo for: {info.Identity.IdentHash}");
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (!info.VerifySignature())
                {
                    Logging.LogDebug($"NetDb: RouterInfo failed signature check: {info.Identity.IdentHash.Id32}");
                    return(false);
                }

                if (!RouterContext.Inst.UseIpV6)
                {
                    if (!info.Adresses.Any(a => a.Options.ValueContains("host", ".")))
                    {
                        Logging.LogDebug($"NetDb: RouterInfo have no IPV4 address: {info.Identity.IdentHash.Id32}");
                        return(false);
                    }
                }

                var meta = new RouterInfoMeta(info.Identity.IdentHash)
                {
                    Updated = true
                };
                var re = new RouterEntry(info, meta);
                RouterInfos[info.Identity.IdentHash] = re;
                if (re.IsFloodfill)
                {
                    FloodfillInfos[info.Identity.IdentHash] = re;
                }
                Logging.LogDebugData($"NetDb: Added RouterInfo for: {info.Identity.IdentHash}");

                Statistics.IsFirewalledUpdate(
                    info.Identity.IdentHash,
                    info.Adresses
                    .Any(a =>
                         a.Options.Any(o =>
                                       o.Key.ToString() == "ihost0")));
            }

            if (RouterInfoUpdates != null)
            {
                ThreadPool.QueueUserWorkItem(a => RouterInfoUpdates(info));
            }

            return(true);
        }