db was overwriting on overlapping CIDRs fffaaaaaaaaaaaacccccccckkkkkk my liffffffeeeeeeee
This commit is contained in:
Binary file not shown.
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/maxmind/mmdbwriter"
|
||||
"github.com/maxmind/mmdbwriter/inserter"
|
||||
"github.com/maxmind/mmdbwriter/mmdbtype"
|
||||
)
|
||||
|
||||
@@ -27,6 +28,9 @@ func run() error {
|
||||
// "1.1.1.1": {
|
||||
// "is_proxy": true,
|
||||
// "score": 42
|
||||
// },
|
||||
// "1.0.0.0/8": {
|
||||
// "is_hosting": true
|
||||
// }
|
||||
// }
|
||||
var input map[string]any
|
||||
@@ -62,6 +66,20 @@ func run() error {
|
||||
}
|
||||
|
||||
// Insert every IP/CIDR.
|
||||
//
|
||||
// Use TopLevelMergeWith instead of the normal Insert method.
|
||||
//
|
||||
// This is important when ranges overlap. For example:
|
||||
//
|
||||
// 1.2.0.0/16 -> {"is_proxy": true}
|
||||
// 1.2.3.0/24 -> {"is_hosting": true}
|
||||
//
|
||||
// An address inside 1.2.3.0/24 will retain both fields:
|
||||
//
|
||||
// {
|
||||
// "is_proxy": true,
|
||||
// "is_hosting": true
|
||||
// }
|
||||
for address, rawRecord := range input {
|
||||
network, err := parseNetwork(address)
|
||||
if err != nil {
|
||||
@@ -73,7 +91,10 @@ func run() error {
|
||||
return fmt.Errorf("invalid record for %q: %w", address, err)
|
||||
}
|
||||
|
||||
if err := tree.Insert(network, record); err != nil {
|
||||
if err := tree.InsertFunc(
|
||||
network,
|
||||
inserter.TopLevelMergeWith(record),
|
||||
); err != nil {
|
||||
return fmt.Errorf("inserting %q: %w", address, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user