github.com/chwjbn/xclash@v0.2.0/constant/provider/interface.go (about)

     1  package provider
     2  
     3  import (
     4  	"github.com/chwjbn/xclash/constant"
     5  )
     6  
     7  // Vehicle Type
     8  const (
     9  	File VehicleType = iota
    10  	HTTP
    11  	Compatible
    12  )
    13  
    14  // VehicleType defined
    15  type VehicleType int
    16  
    17  func (v VehicleType) String() string {
    18  	switch v {
    19  	case File:
    20  		return "File"
    21  	case HTTP:
    22  		return "HTTP"
    23  	case Compatible:
    24  		return "Compatible"
    25  	default:
    26  		return "Unknown"
    27  	}
    28  }
    29  
    30  type Vehicle interface {
    31  	Read() ([]byte, error)
    32  	Path() string
    33  	Type() VehicleType
    34  }
    35  
    36  // Provider Type
    37  const (
    38  	Proxy ProviderType = iota
    39  	Rule
    40  )
    41  
    42  // ProviderType defined
    43  type ProviderType int
    44  
    45  func (pt ProviderType) String() string {
    46  	switch pt {
    47  	case Proxy:
    48  		return "Proxy"
    49  	case Rule:
    50  		return "Rule"
    51  	default:
    52  		return "Unknown"
    53  	}
    54  }
    55  
    56  // Provider interface
    57  type Provider interface {
    58  	Name() string
    59  	VehicleType() VehicleType
    60  	Type() ProviderType
    61  	Initial() error
    62  	Update() error
    63  }
    64  
    65  // ProxyProvider interface
    66  type ProxyProvider interface {
    67  	Provider
    68  	Proxies() []constant.Proxy
    69  	// ProxiesWithTouch is used to inform the provider that the proxy is actually being used while getting the list of proxies.
    70  	// Commonly used in DialContext and DialPacketConn
    71  	ProxiesWithTouch() []constant.Proxy
    72  	HealthCheck()
    73  }
    74  
    75  // Rule Type
    76  const (
    77  	Domain RuleType = iota
    78  	IPCIDR
    79  	Classical
    80  )
    81  
    82  // RuleType defined
    83  type RuleType int
    84  
    85  func (rt RuleType) String() string {
    86  	switch rt {
    87  	case Domain:
    88  		return "Domain"
    89  	case IPCIDR:
    90  		return "IPCIDR"
    91  	case Classical:
    92  		return "Classical"
    93  	default:
    94  		return "Unknown"
    95  	}
    96  }
    97  
    98  // RuleProvider interface
    99  type RuleProvider interface {
   100  	Provider
   101  	Behavior() RuleType
   102  	Match(*constant.Metadata) bool
   103  	ShouldResolveIP() bool
   104  	AsRule(adaptor string) constant.Rule
   105  }