mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-07-26 11:44:22 -04:00
Add Persistence for Subscription imports
This commit is contained in:
parent
45e741bae0
commit
713a7cf49e
@ -98,6 +98,7 @@ type Config struct {
|
||||
Imports []*ImportSource `protobuf:"bytes,1,rep,name=imports,proto3" json:"imports,omitempty"`
|
||||
NonnativeConverterOverlay []byte `protobuf:"bytes,2,opt,name=nonnative_converter_overlay,json=nonnativeConverterOverlay,proto3" json:"nonnative_converter_overlay,omitempty"`
|
||||
NonnativeConverterOverlayFile string `protobuf:"bytes,96002,opt,name=nonnative_converter_overlay_file,json=nonnativeConverterOverlayFile,proto3" json:"nonnative_converter_overlay_file,omitempty"`
|
||||
Persistence bool `protobuf:"varint,3,opt,name=persistence,proto3" json:"persistence,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@ -153,6 +154,13 @@ func (x *Config) GetNonnativeConverterOverlayFile() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Config) GetPersistence() bool {
|
||||
if x != nil {
|
||||
return x.Persistence
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var File_app_subscription_config_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_app_subscription_config_proto_rawDesc = string([]byte{
|
||||
@ -173,7 +181,7 @@ var file_app_subscription_config_proto_rawDesc = string([]byte{
|
||||
0x0a, 0x16, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65,
|
||||
0x5f, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x14,
|
||||
0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x53, 0x65, 0x63,
|
||||
0x6f, 0x6e, 0x64, 0x73, 0x22, 0x98, 0x02, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12,
|
||||
0x6f, 0x6e, 0x64, 0x73, 0x22, 0xba, 0x02, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12,
|
||||
0x43, 0x0a, 0x07, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
|
||||
0x32, 0x29, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70,
|
||||
0x70, 0x2e, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x49,
|
||||
@ -189,16 +197,18 @@ var file_app_subscription_config_proto_rawDesc = string([]byte{
|
||||
0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x72, 0x5f, 0x6f, 0x76, 0x65, 0x72,
|
||||
0x6c, 0x61, 0x79, 0x52, 0x1d, 0x6e, 0x6f, 0x6e, 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x43, 0x6f,
|
||||
0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x72, 0x4f, 0x76, 0x65, 0x72, 0x6c, 0x61, 0x79, 0x46, 0x69,
|
||||
0x6c, 0x65, 0x3a, 0x1b, 0x82, 0xb5, 0x18, 0x17, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63,
|
||||
0x65, 0x12, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x42,
|
||||
0x72, 0x0a, 0x1f, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72,
|
||||
0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x50, 0x01, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
|
||||
0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72,
|
||||
0x65, 0x2f, 0x76, 0x35, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69,
|
||||
0x70, 0x74, 0x69, 0x6f, 0x6e, 0xaa, 0x02, 0x1b, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f,
|
||||
0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x6c, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e, 0x63,
|
||||
0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x70, 0x65, 0x72, 0x73, 0x69, 0x73, 0x74,
|
||||
0x65, 0x6e, 0x63, 0x65, 0x3a, 0x1b, 0x82, 0xb5, 0x18, 0x17, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76,
|
||||
0x69, 0x63, 0x65, 0x12, 0x0c, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x42, 0x72, 0x0a, 0x1f, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63,
|
||||
0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70,
|
||||
0x74, 0x69, 0x6f, 0x6e, 0x50, 0x01, 0x5a, 0x2f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63,
|
||||
0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63,
|
||||
0x6f, 0x72, 0x65, 0x2f, 0x76, 0x35, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x73, 0x75, 0x62, 0x73, 0x63,
|
||||
0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0xaa, 0x02, 0x1b, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e,
|
||||
0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69,
|
||||
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
})
|
||||
|
||||
var (
|
||||
|
@ -28,4 +28,6 @@ message Config {
|
||||
|
||||
bytes nonnative_converter_overlay = 2;
|
||||
string nonnative_converter_overlay_file = 96002 [(v2ray.core.common.protoext.field_opt).convert_time_read_file_into = "nonnative_converter_overlay"];
|
||||
|
||||
bool persistence = 3;
|
||||
}
|
@ -72,6 +72,7 @@ type TrackedSubscriptionStatus struct {
|
||||
Servers map[string]*SubscriptionServer `protobuf:"bytes,1,rep,name=servers,proto3" json:"servers,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
DocumentMetadata map[string]string `protobuf:"bytes,2,rep,name=documentMetadata,proto3" json:"documentMetadata,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
|
||||
ImportSource *ImportSource `protobuf:"bytes,3,opt,name=importSource,proto3" json:"importSource,omitempty"`
|
||||
AddedByApi bool `protobuf:"varint,4,opt,name=added_by_api,json=addedByApi,proto3" json:"added_by_api,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@ -127,6 +128,13 @@ func (x *TrackedSubscriptionStatus) GetImportSource() *ImportSource {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *TrackedSubscriptionStatus) GetAddedByApi() bool {
|
||||
if x != nil {
|
||||
return x.AddedByApi
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var File_app_subscription_subscription_rpc_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_app_subscription_subscription_rpc_proto_rawDesc = string([]byte{
|
||||
@ -149,8 +157,8 @@ var file_app_subscription_subscription_rpc_proto_rawDesc = string([]byte{
|
||||
0x65, 0x72, 0x76, 0x65, 0x72, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74,
|
||||
0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xf5,
|
||||
0x03, 0x0a, 0x19, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72,
|
||||
0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x97,
|
||||
0x04, 0x0a, 0x19, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x64, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72,
|
||||
0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x5d, 0x0a, 0x07,
|
||||
0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x43, 0x2e,
|
||||
0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x73,
|
||||
@ -170,26 +178,28 @@ var file_app_subscription_subscription_rpc_proto_rawDesc = string([]byte{
|
||||
0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x73, 0x75, 0x62,
|
||||
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x49, 0x6d, 0x70, 0x6f, 0x72, 0x74,
|
||||
0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x52, 0x0c, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x53, 0x6f,
|
||||
0x75, 0x72, 0x63, 0x65, 0x1a, 0x6b, 0x0a, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x45,
|
||||
0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x45, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2f, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f,
|
||||
0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
|
||||
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38,
|
||||
0x01, 0x1a, 0x43, 0x0a, 0x15, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x74,
|
||||
0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65,
|
||||
0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05,
|
||||
0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c,
|
||||
0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x72, 0x0a, 0x1f, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32,
|
||||
0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x73, 0x75, 0x62,
|
||||
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x01, 0x5a, 0x2f, 0x67, 0x69, 0x74,
|
||||
0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32,
|
||||
0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x35, 0x2f, 0x61, 0x70, 0x70, 0x2f,
|
||||
0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0xaa, 0x02, 0x1b, 0x56,
|
||||
0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x53, 0x75,
|
||||
0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
0x75, 0x72, 0x63, 0x65, 0x12, 0x20, 0x0a, 0x0c, 0x61, 0x64, 0x64, 0x65, 0x64, 0x5f, 0x62, 0x79,
|
||||
0x5f, 0x61, 0x70, 0x69, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x61, 0x64, 0x64, 0x65,
|
||||
0x64, 0x42, 0x79, 0x41, 0x70, 0x69, 0x1a, 0x6b, 0x0a, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
|
||||
0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x45, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75,
|
||||
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2f, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e,
|
||||
0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69,
|
||||
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a,
|
||||
0x02, 0x38, 0x01, 0x1a, 0x43, 0x0a, 0x15, 0x44, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x4d,
|
||||
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
|
||||
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14,
|
||||
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76,
|
||||
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x72, 0x0a, 0x1f, 0x63, 0x6f, 0x6d, 0x2e,
|
||||
0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x73,
|
||||
0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x50, 0x01, 0x5a, 0x2f, 0x67,
|
||||
0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f,
|
||||
0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x35, 0x2f, 0x61, 0x70,
|
||||
0x70, 0x2f, 0x73, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0xaa, 0x02,
|
||||
0x1b, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e,
|
||||
0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
})
|
||||
|
||||
var (
|
||||
|
@ -18,4 +18,6 @@ message TrackedSubscriptionStatus {
|
||||
map<string, SubscriptionServer> servers = 1;
|
||||
map<string, string> documentMetadata = 2;
|
||||
v2ray.core.app.subscription.ImportSource importSource = 3;
|
||||
|
||||
bool added_by_api = 4;
|
||||
}
|
@ -8,11 +8,15 @@ import (
|
||||
"time"
|
||||
|
||||
core "github.com/v2fly/v2ray-core/v5"
|
||||
"github.com/v2fly/v2ray-core/v5/app/persistentstorage"
|
||||
"github.com/v2fly/v2ray-core/v5/app/persistentstorage/protostorage"
|
||||
"github.com/v2fly/v2ray-core/v5/app/subscription"
|
||||
"github.com/v2fly/v2ray-core/v5/app/subscription/entries"
|
||||
"github.com/v2fly/v2ray-core/v5/app/subscription/entries/nonnative/nonnativeifce"
|
||||
"github.com/v2fly/v2ray-core/v5/app/subscription/specs"
|
||||
"github.com/v2fly/v2ray-core/v5/common"
|
||||
"github.com/v2fly/v2ray-core/v5/common/environment"
|
||||
"github.com/v2fly/v2ray-core/v5/common/environment/envctx"
|
||||
"github.com/v2fly/v2ray-core/v5/common/task"
|
||||
)
|
||||
|
||||
@ -29,6 +33,10 @@ type SubscriptionManagerImpl struct {
|
||||
trackedSubscriptions map[string]*trackedSubscription
|
||||
|
||||
refreshTask *task.Periodic
|
||||
|
||||
persistentStorage persistentstorage.ScopedPersistentStorage
|
||||
persistImportStorage persistentstorage.ScopedPersistentStorage
|
||||
persistImportSourceProtoStorage protostorage.ProtoPersistentStorage
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerImpl) Type() interface{} {
|
||||
@ -47,6 +55,20 @@ func (s *SubscriptionManagerImpl) housekeeping() error {
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerImpl) Start() error {
|
||||
if s.config.Persistence {
|
||||
appEnvironment := envctx.EnvironmentFromContext(s.ctx).(environment.AppEnvironment)
|
||||
s.persistentStorage = appEnvironment.PersistentStorage()
|
||||
|
||||
importsStorage, err := s.persistentStorage.NarrowScope(s.ctx, []byte("imports"))
|
||||
if err != nil {
|
||||
return newError("failed to get persistent storage for imports").Base(err)
|
||||
}
|
||||
s.persistImportStorage = importsStorage
|
||||
s.persistImportSourceProtoStorage = importsStorage.(protostorage.ProtoPersistentStorage)
|
||||
if err = s.loadAllFromPersistentStorage(); err != nil {
|
||||
newError("failed to load all from persistent storage: ", err).WriteToLog()
|
||||
}
|
||||
}
|
||||
go func() {
|
||||
if err := s.refreshTask.Start(); err != nil {
|
||||
return
|
||||
@ -62,16 +84,32 @@ func (s *SubscriptionManagerImpl) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerImpl) addTrackedSubscriptionFromImportSource(importSource *subscription.ImportSource) error {
|
||||
func (s *SubscriptionManagerImpl) addTrackedSubscriptionFromImportSource(importSource *subscription.ImportSource,
|
||||
addedByAPI bool,
|
||||
) error {
|
||||
if s.config.Persistence && addedByAPI {
|
||||
err := s.persistImportSourceProtoStorage.PutProto(s.ctx, importSource.Name, importSource)
|
||||
if err != nil {
|
||||
return newError("failed to persist import source: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
tracked, err := newTrackedSubscription(importSource)
|
||||
if err != nil {
|
||||
return newError("failed to init subscription ", importSource.Name, ": ", err)
|
||||
}
|
||||
tracked.addedByAPI = addedByAPI
|
||||
s.trackedSubscriptions[importSource.Name] = tracked
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerImpl) removeTrackedSubscription(subscriptionName string) error {
|
||||
if s.config.Persistence {
|
||||
err := s.persistImportStorage.Put(s.ctx, []byte(subscriptionName), nil)
|
||||
if err != nil {
|
||||
return newError("failed to delete import source: ", err)
|
||||
}
|
||||
}
|
||||
if _, ok := s.trackedSubscriptions[subscriptionName]; ok {
|
||||
err := s.applySubscriptionTo(subscriptionName, &specs.SubscriptionDocument{Server: make([]*specs.SubscriptionServerConfig, 0)})
|
||||
if err != nil {
|
||||
@ -104,7 +142,28 @@ func (s *SubscriptionManagerImpl) init() error {
|
||||
}
|
||||
|
||||
for _, v := range s.config.Imports {
|
||||
if err := s.addTrackedSubscriptionFromImportSource(v); err != nil {
|
||||
if err := s.addTrackedSubscriptionFromImportSource(v, false); err != nil {
|
||||
return newError("failed to add tracked subscription: ", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerImpl) loadAllFromPersistentStorage() error {
|
||||
if !s.config.Persistence {
|
||||
return nil
|
||||
}
|
||||
protoImportSources, err := s.persistImportStorage.List(s.ctx, []byte(""))
|
||||
if err != nil {
|
||||
return newError("failed to list import sources: ", err)
|
||||
}
|
||||
for _, protoImportSource := range protoImportSources {
|
||||
var importSource subscription.ImportSource
|
||||
err := s.persistImportSourceProtoStorage.GetProto(s.ctx, string(protoImportSource), &importSource)
|
||||
if err != nil {
|
||||
return newError("failed to get import source: ", err)
|
||||
}
|
||||
if err := s.addTrackedSubscriptionFromImportSource(&importSource, false); err != nil {
|
||||
return newError("failed to add tracked subscription: ", err)
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import "github.com/v2fly/v2ray-core/v5/app/subscription"
|
||||
func (s *SubscriptionManagerImpl) AddTrackedSubscriptionFromImportSource(importSource *subscription.ImportSource) error {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.addTrackedSubscriptionFromImportSource(importSource)
|
||||
return s.addTrackedSubscriptionFromImportSource(importSource, true)
|
||||
}
|
||||
|
||||
func (s *SubscriptionManagerImpl) RemoveTrackedSubscription(name string) error {
|
||||
|
@ -23,6 +23,8 @@ type trackedSubscription struct {
|
||||
originalDocument []byte
|
||||
originalContainer *containers.Container
|
||||
originalServerConfig map[string]*originalServerConfig
|
||||
|
||||
addedByAPI bool
|
||||
}
|
||||
|
||||
type originalServerConfig struct {
|
||||
@ -92,5 +94,6 @@ func (s *trackedSubscription) fillStatus(status *subscription.TrackedSubscriptio
|
||||
status.Servers[v.Id].Tag = materializedInstance.tagPostfix
|
||||
}
|
||||
}
|
||||
status.AddedByApi = s.addedByAPI
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user