Skip to content

Commit

Permalink
Add support for geosite.dat
Browse files Browse the repository at this point in the history
  • Loading branch information
yuguorui committed Apr 19, 2022
1 parent 11d3fcd commit fe64242
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
config.*ml
*.mmdb
src/protos/common.rs
.gitback/
142 changes: 142 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ tuple = "0.5.1"
clap = { version = "3.0.14", features = ["derive"] }
anyhow = "1.0"
thiserror = "1.0"
protobuf = "2.27.1"

[target.'cfg(target_os = "linux")'.dependencies]
iptables = "*"
rtnetlink = "0.9.0"

[build-dependencies]
protoc-rust = "2"
protoc-bin-vendored = "3.0.0"
12 changes: 12 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extern crate protoc_rust;

fn main() {

protoc_rust::Codegen::new()
.protoc_path(protoc_bin_vendored::protoc_bin_path().unwrap())
.out_dir("src/protos")
.inputs(&["protos/common.proto"])
.includes([".", protoc_bin_vendored::include_path().unwrap().to_str().unwrap()])
.run()
.expect("Running protoc failed.");
}
85 changes: 85 additions & 0 deletions protos/common.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
syntax = "proto3";

package v2ray.core.app.router.routercommon;
option csharp_namespace = "V2Ray.Core.App.Router.Routercommon";
option go_package = "github.com/v2fly/v2ray-core/v5/app/router/routercommon";
option java_package = "com.v2ray.core.app.router.routercommon";
option java_multiple_files = true;


import "protos/extensions.proto";

// Domain for routing decision.
message Domain {
// Type of domain value.
enum Type {
// The value is used as is.
Plain = 0;
// The value is used as a regular expression.
Regex = 1;
// The value is a root domain.
RootDomain = 2;
// The value is a domain.
Full = 3;
}

// Domain matching type.
Type type = 1;

// Domain value.
string value = 2;

message Attribute {
string key = 1;

oneof typed_value {
bool bool_value = 2;
int64 int_value = 3;
}
}

// Attributes of this domain. May be used for filtering.
repeated Attribute attribute = 3;
}

// IP for routing decision, in CIDR form.
message CIDR {
// IP address, should be either 4 or 16 bytes.
bytes ip = 1;

// Number of leading ones in the network mask.
uint32 prefix = 2;

string ip_addr = 68000 [(v2ray.core.common.protoext.field_opt).convert_time_parse_ip = "ip"];
}

message GeoIP {
string country_code = 1;
repeated CIDR cidr = 2;
bool inverse_match = 3;

// resource_hash instruct simplified config converter to load domain from geo file.
bytes resource_hash = 4;
string code = 5;

string file_path = 68000[(v2ray.core.common.protoext.field_opt).convert_time_resource_loading = "resource_hash"];
}

message GeoIPList {
repeated GeoIP entry = 1;
}

message GeoSite {
string country_code = 1;
repeated Domain domain = 2;

// resource_hash instruct simplified config converter to load domain from geo file.
bytes resource_hash = 3;
string code = 4;

string file_path = 68000[(v2ray.core.common.protoext.field_opt).convert_time_resource_loading = "resource_hash"];
}

message GeoSiteList {
repeated GeoSite entry = 1;
}
39 changes: 39 additions & 0 deletions protos/extensions.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
syntax = "proto3";

package v2ray.core.common.protoext;
option csharp_namespace = "V2Ray.Core.Common.ProtoExt";
option go_package = "github.com/v2fly/v2ray-core/v5/common/protoext";
option java_package = "com.v2ray.core.common.protoext";
option java_multiple_files = true;

import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {
MessageOpt message_opt = 50000;
}

extend google.protobuf.FieldOptions {
FieldOpt field_opt = 50000;
}

message MessageOpt{
repeated string type = 1;
repeated string short_name = 2;

string transport_original_name = 86001;
}

message FieldOpt{
repeated string any_wants = 1;
repeated string allowed_values = 2;
repeated string allowed_value_types = 3;

// convert_time_read_file_into read a file into another field, and clear this field during input parsing
string convert_time_read_file_into = 4;
// forbidden marks a boolean to be inaccessible to user
bool forbidden = 5;
// convert_time_resource_loading read a file, and place its resource hash into another field
string convert_time_resource_loading = 6;
// convert_time_parse_ip parse a string ip address, and put its binary representation into another field
string convert_time_parse_ip = 7;
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod rules;
mod protos;
mod settings;
mod socks5;

Expand Down
1 change: 1 addition & 0 deletions src/protos/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod common;
Loading

0 comments on commit fe64242

Please sign in to comment.