Loyalsoldier / geoip

🌚 🌍 🌝 GeoIP 规则文件加强版,支持自行定制 V2Ray dat 格式文件 geoip.dat、MaxMind mmdb 格式文件、sing-box SRS 格式文件、mihomo MRS 格式文件、Clash ruleset、Surge ruleset 等。Enhanced edition of GeoIP files for V2Ray, Xray-core, sing-box, Clash, mihomo, Shadowrocket, Quantumult X, Surge, hysteria, Trojan-Go, Leaf, Nginx, etc.
Creative Commons Attribution Share Alike 4.0 International
3.98k stars 664 forks source link

v2ray 的protobuf文件好像更新了,我目前用v2ray的protobuf解析不了 #170

Closed kitty-eu-org closed 6 months ago

kitty-eu-org commented 6 months ago

v2ray 的protobuf文件好像更新了,我目前用v2ray的protobuf解析不了 用v2ray的proto解析v2ray的dat文件是可以的?如何用大佬的dat,如何解析呢?有.proto吗?

Loyalsoldier commented 6 months ago

什么意思?把 geoip.dat 文件下载下来,放到 v2ray 目录下,在配置文件中添加诸如 geoip:cn 的规则就可以使用啊。

kitty-eu-org commented 6 months ago

我写了一个解析dat的项目,我copy的v2ray-core的proto文件:https://github.com/hezhaozhao-git/kitty_proxy/tree/main/src/protoes 但是解析不了大佬你提供的这个dat文件,用v2ray-core提供的dat文件就可以

kitty-eu-org commented 6 months ago

没事了,我用xray-core的proto文件可以解析,但是v2ray-core的不行,多谢了,也就是现在的dat文件跟v2ray-core项目不兼容

Loyalsoldier commented 6 months ago

确实是更新了,见:https://github.com/v2fly/v2ray-core/blob/master/app/router/routercommon/common.proto

kitty-eu-org commented 6 months ago

是的,我用了xray-core的proto文件可以解析大佬提供的dat 文件

Loyalsoldier commented 6 months ago

本项目也写了解析代码啊,不是这样吗?

https://github.com/Loyalsoldier/geoip/blob/09fed9bfdfa2319cac484701145306be127a3dd9/plugin/v2ray/dat_in.go#L165-L204

kitty-eu-org commented 6 months ago

本项目也写了解析代码啊,不是这样吗?

https://github.com/Loyalsoldier/geoip/blob/09fed9bfdfa2319cac484701145306be127a3dd9/plugin/v2ray/dat_in.go#L165-L204

是这样的,但是我没看到你的proto文件,,,你应该是copy protoc生成后的go代码吧,我是用proto生成rust代码

Loyalsoldier commented 6 months ago

我试了一下,proto 文件写成这样就可以了:

syntax = "proto3";

package v2ray_config;

// 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;
}

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

message GeoIPList {
  repeated GeoIP entry = 1;
}

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

message GeoSiteList {
  repeated GeoSite entry = 1;
}