Darien Raymond il y a 7 ans
Parent
commit
20fc4950b2
4 fichiers modifiés avec 29 ajouts et 5 suppressions
  1. 6 0
      common/signal/done.go
  2. 4 0
      common/signal/notifier.go
  3. 6 1
      common/signal/task.go
  4. 13 4
      main/distro/all/all.go

+ 6 - 0
common/signal/done.go

@@ -4,18 +4,21 @@ import (
 	"sync"
 )
 
+// Done is an utility for notifications of something being done.
 type Done struct {
 	access sync.Mutex
 	c      chan struct{}
 	closed bool
 }
 
+// NewDone returns a new Done.
 func NewDone() *Done {
 	return &Done{
 		c: make(chan struct{}),
 	}
 }
 
+// Done returns true if Close() is called.
 func (d *Done) Done() bool {
 	select {
 	case <-d.c:
@@ -25,14 +28,17 @@ func (d *Done) Done() bool {
 	}
 }
 
+// C returns a channel for waiting for done.
 func (d *Done) C() chan struct{} {
 	return d.c
 }
 
+// Wait blocks until Close() is called.
 func (d *Done) Wait() {
 	<-d.c
 }
 
+// Close marks this Done 'done'. This method may be called mutliple times. All calls after first call will have no effect on its status.
 func (d *Done) Close() error {
 	d.access.Lock()
 	defer d.access.Unlock()

+ 4 - 0
common/signal/notifier.go

@@ -1,15 +1,18 @@
 package signal
 
+// Notifier is an utility for notifying changes. The change producer may notify changes multiple time, and the consumer may get notified asychronously.
 type Notifier struct {
 	c chan struct{}
 }
 
+// NewNotifier creates a new Notifier.
 func NewNotifier() *Notifier {
 	return &Notifier{
 		c: make(chan struct{}, 1),
 	}
 }
 
+// Signal signals a change, usually by producer. This method never blocks.
 func (n *Notifier) Signal() {
 	select {
 	case n.c <- struct{}{}:
@@ -17,6 +20,7 @@ func (n *Notifier) Signal() {
 	}
 }
 
+// Wait returns a channel for waiting for changes. The returned channel never gets closed.
 func (n *Notifier) Wait() <-chan struct{} {
 	return n.c
 }

+ 6 - 1
common/signal/task.go

@@ -5,9 +5,12 @@ import (
 	"time"
 )
 
+// PeriodicTask is a task that runs periodically.
 type PeriodicTask struct {
+	// Interval of the task being run
 	Interval time.Duration
-	Execute  func() error
+	// Execute is the task function
+	Execute func() error
 
 	access sync.Mutex
 	timer  *time.Timer
@@ -33,6 +36,7 @@ func (t *PeriodicTask) checkedExecute() error {
 	return nil
 }
 
+// Start implements common.Runnable. Start must not be called multiple times without Close being called.
 func (t *PeriodicTask) Start() error {
 	t.access.Lock()
 	t.closed = false
@@ -46,6 +50,7 @@ func (t *PeriodicTask) Start() error {
 	return nil
 }
 
+// Close implements common.Runnable.
 func (t *PeriodicTask) Close() error {
 	t.access.Lock()
 	defer t.access.Unlock()

+ 13 - 4
main/distro/all/all.go

@@ -2,16 +2,23 @@ package all
 
 import (
 	// The following are necessary as they register handlers in their init functions.
-	_ "v2ray.com/core/app/commander"
+
+	// Required features. Can't remove unless there is replacements.
 	_ "v2ray.com/core/app/dispatcher"
+	_ "v2ray.com/core/app/proxyman/inbound"
+	_ "v2ray.com/core/app/proxyman/outbound"
+
+	// Default commander and all its services.
+	_ "v2ray.com/core/app/commander"
+	_ "v2ray.com/core/app/proxyman/command"
+
+	// Other optional features.
 	_ "v2ray.com/core/app/dns"
 	_ "v2ray.com/core/app/log"
 	_ "v2ray.com/core/app/policy"
-	_ "v2ray.com/core/app/proxyman/command"
-	_ "v2ray.com/core/app/proxyman/inbound"
-	_ "v2ray.com/core/app/proxyman/outbound"
 	_ "v2ray.com/core/app/router"
 
+	// Inbound and outbound proxies.
 	_ "v2ray.com/core/proxy/blackhole"
 	_ "v2ray.com/core/proxy/dokodemo"
 	_ "v2ray.com/core/proxy/freedom"
@@ -21,12 +28,14 @@ import (
 	_ "v2ray.com/core/proxy/vmess/inbound"
 	_ "v2ray.com/core/proxy/vmess/outbound"
 
+	// Transports
 	_ "v2ray.com/core/transport/internet/kcp"
 	_ "v2ray.com/core/transport/internet/tcp"
 	_ "v2ray.com/core/transport/internet/tls"
 	_ "v2ray.com/core/transport/internet/udp"
 	_ "v2ray.com/core/transport/internet/websocket"
 
+	// Transport headers
 	_ "v2ray.com/core/transport/internet/headers/http"
 	_ "v2ray.com/core/transport/internet/headers/noop"
 	_ "v2ray.com/core/transport/internet/headers/srtp"