Skip to content

Commit 28fa84c

Browse files
committed
API doc
1 parent 05f8de1 commit 28fa84c

File tree

11 files changed

+60
-0
lines changed

11 files changed

+60
-0
lines changed

annotations.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package core
2+
3+
// Annotation is a concept in V2Ray. This struct is only for documentation. It is not used anywhere.
4+
// Annotations begin with "v2ray:" in comment, as metadata of functions or types.
5+
type Annotation struct {
6+
// API is for types or functions that can be used in other libs. Possible values are:
7+
//
8+
// * v2ray:api:beta for types or functions that are ready for use, but maybe changed in the future.
9+
// * v2ray:api:stable for types or functions with guarantee of backward compatibility.
10+
// * v2ray:api:deprecated for types or functions that should not be used anymore.
11+
//
12+
// Types or functions without api annotation should not be used externally.
13+
API string
14+
}

features/dns/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
)
77

88
// Client is a V2Ray feature for querying DNS information.
9+
//
10+
// v2ray:api:stable
911
type Client interface {
1012
features.Feature
1113

@@ -14,16 +16,22 @@ type Client interface {
1416
}
1517

1618
// IPv4Lookup is an optional feature for querying IPv4 addresses only.
19+
//
20+
// v2ray:api:beta
1721
type IPv4Lookup interface {
1822
LookupIPv4(domain string) ([]net.IP, error)
1923
}
2024

2125
// IPv6Lookup is an optional feature for querying IPv6 addresses only.
26+
//
27+
// v2ray:api:beta
2228
type IPv6Lookup interface {
2329
LookupIPv6(domain string) ([]net.IP, error)
2430
}
2531

2632
// ClientType returns the type of Client interface. Can be used for implementing common.HasType.
33+
//
34+
// v2ray:api:beta
2735
func ClientType() interface{} {
2836
return (*Client)(nil)
2937
}

features/inbound/inbound.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
// Handler is the interface for handlers that process inbound connections.
12+
//
13+
// v2ray:api:stable
1214
type Handler interface {
1315
common.Runnable
1416
// The tag of this handler.
@@ -19,6 +21,8 @@ type Handler interface {
1921
}
2022

2123
// Manager is a feature that manages InboundHandlers.
24+
//
25+
// v2ray:api:stable
2226
type Manager interface {
2327
features.Feature
2428
// GetHandlers returns an InboundHandler for the given tag.
@@ -31,6 +35,8 @@ type Manager interface {
3135
}
3236

3337
// ManagerType returns the type of Manager interface. Can be used for implementing common.HasType.
38+
//
39+
// v2ray:api:stable
3440
func ManagerType() interface{} {
3541
return (*Manager)(nil)
3642
}

features/outbound/outbound.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
// Handler is the interface for handlers that process outbound connections.
12+
//
13+
// v2ray:api:stable
1214
type Handler interface {
1315
common.Runnable
1416
Tag() string
@@ -20,6 +22,8 @@ type HandlerSelector interface {
2022
}
2123

2224
// Manager is a feature that manages outbound.Handlers.
25+
//
26+
// v2ray:api:stable
2327
type Manager interface {
2428
features.Feature
2529
// GetHandler returns an outbound.Handler for the given tag.
@@ -34,6 +38,8 @@ type Manager interface {
3438
}
3539

3640
// ManagerType returns the type of Manager interface. Can be used to implement common.HasType.
41+
//
42+
// v2ray:api:stable
3743
func ManagerType() interface{} {
3844
return (*Manager)(nil)
3945
}

features/policy/policy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type Session struct {
5757
}
5858

5959
// Manager is a feature that provides Policy for the given user by its id or level.
60+
//
61+
// v2ray:api:stable
6062
type Manager interface {
6163
features.Feature
6264

@@ -68,6 +70,8 @@ type Manager interface {
6870
}
6971

7072
// ManagerType returns the type of Manager interface. Can be used to implement common.HasType.
73+
//
74+
// v2ray:api:stable
7175
func ManagerType() interface{} {
7276
return (*Manager)(nil)
7377
}

features/routing/dispatcher.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
// Dispatcher is a feature that dispatches inbound requests to outbound handlers based on rules.
1212
// Dispatcher is required to be registered in a V2Ray instance to make V2Ray function properly.
13+
//
14+
// v2ray:api:stable
1315
type Dispatcher interface {
1416
features.Feature
1517

@@ -18,6 +20,8 @@ type Dispatcher interface {
1820
}
1921

2022
// DispatcherType returns the type of Dispatcher interface. Can be used to implement common.HasType.
23+
//
24+
// v2ray:api:stable
2125
func DispatcherType() interface{} {
2226
return (*Dispatcher)(nil)
2327
}

features/routing/router.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
)
99

1010
// Router is a feature to choose an outbound tag for the given request.
11+
//
12+
// v2ray:api:stable
1113
type Router interface {
1214
features.Feature
1315

@@ -16,6 +18,8 @@ type Router interface {
1618
}
1719

1820
// RouterType return the type of Router interface. Can be used to implement common.HasType.
21+
//
22+
// v2ray:api:stable
1923
func RouterType() interface{} {
2024
return (*Router)(nil)
2125
}

features/stats/stats.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package stats
55
import "v2ray.com/core/features"
66

77
// Counter is the interface for stats counters.
8+
//
9+
// v2ray:api:stable
810
type Counter interface {
911
// Value is the current value of the counter.
1012
Value() int64
@@ -15,6 +17,8 @@ type Counter interface {
1517
}
1618

1719
// Manager is the interface for stats manager.
20+
//
21+
// v2ray:api:stable
1822
type Manager interface {
1923
features.Feature
2024

@@ -35,6 +39,8 @@ func GetOrRegisterCounter(m Manager, name string) (Counter, error) {
3539
}
3640

3741
// ManagerType returns the type of Manager interface. Can be used to implement common.HasType.
42+
//
43+
// v2ray:api:stable
3844
func ManagerType() interface{} {
3945
return (*Manager)(nil)
4046
}

functions.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func CreateObject(v *Instance, config interface{}) (interface{}, error) {
2020

2121
// StartInstance starts a new V2Ray instance with given serialized config.
2222
// By default V2Ray only support config in protobuf format, i.e., configFormat = "protobuf". Caller need to load other packages to add JSON support.
23+
//
24+
// v2ray:api:stable
2325
func StartInstance(configFormat string, configBytes []byte) (*Instance, error) {
2426
config, err := LoadConfig(configFormat, "", bytes.NewReader(configBytes))
2527
if err != nil {
@@ -39,6 +41,8 @@ func StartInstance(configFormat string, configBytes []byte) (*Instance, error) {
3941
// It dispatches the request to the given destination by the given V2Ray instance.
4042
// Since it is under a proxy context, the LocalAddr() and RemoteAddr() in returned net.Conn
4143
// will not show real addresses being used for communication.
44+
//
45+
// v2ray:api:stable
4246
func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error) {
4347
dispatcher := v.GetFeature(routing.DispatcherType())
4448
if dispatcher == nil {

transport/internet/system_dialer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func (v *SimpleSystemDialer) Dial(ctx context.Context, src net.Address, dest net
7979

8080
// UseAlternativeSystemDialer replaces the current system dialer with a given one.
8181
// Caller must ensure there is no race condition.
82+
//
83+
// v2ray:api:stable
8284
func UseAlternativeSystemDialer(dialer SystemDialer) {
8385
if dialer == nil {
8486
effectiveSystemDialer = DefaultSystemDialer{}

v2ray.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ func (s *Instance) GetFeature(featureType interface{}) features.Feature {
303303

304304
// Start starts the V2Ray instance, including all registered features. When Start returns error, the state of the instance is unknown.
305305
// A V2Ray instance can be started only once. Upon closing, the instance is not guaranteed to start again.
306+
//
307+
// v2ray:api:stable
306308
func (s *Instance) Start() error {
307309
s.access.Lock()
308310
defer s.access.Unlock()

0 commit comments

Comments
 (0)