Giter VIP home page Giter VIP logo

Comments (3)

cenkalti avatar cenkalti commented on May 24, 2024

IPv4 address range is 32 bits and the memory cost of storing each address separately in a map would be too high.
For the same reason blocklists are usually distributed in CIDR format. Segment tree is a data structure to allow fast (O(logn)) lookups within stored ranges.

Segment tree: https://en.wikipedia.org/wiki/Segment_tree

Original implementation: https://github.com/toberndo/go-stree

Example list source: https://www.iblocklist.com/lists?fileformat=cidr&archiveformat=gz

Doc:

// URL to the blocklist file in CIDR format.

I don't use Discord but you can email me for other questions.

from rain.

ruralcoder avatar ruralcoder commented on May 24, 2024

Cool, thanks. I will email you.

One cool thing about golang is that keys don't need to be strings.

So your key could easily be a 32bit int, though you lose 1 byte in the bool. But then each of your tree nodes use 2x 8byte for the left, right pointers.

map[int32]bool{ ipA: true, ipB: true }

Now perhaps your blocklist is not used much hence not an issue.

Was playing with rain on the command like to see how it works....really cool. Works like a charm.

from rain.

cenkalti avatar cenkalti commented on May 24, 2024

The memory space is one part of the problem. The other one is searching. How do you check if an address is blocked by one of the ranges in the blocklist with a map type?

from rain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.