1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 14:26:11 -04:00
This commit is contained in:
Darien Raymond 2018-02-11 23:28:42 +01:00
parent 997c852be8
commit 20fc4950b2
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 29 additions and 5 deletions

View File

@ -4,18 +4,21 @@ import (
"sync" "sync"
) )
// Done is an utility for notifications of something being done.
type Done struct { type Done struct {
access sync.Mutex access sync.Mutex
c chan struct{} c chan struct{}
closed bool closed bool
} }
// NewDone returns a new Done.
func NewDone() *Done { func NewDone() *Done {
return &Done{ return &Done{
c: make(chan struct{}), c: make(chan struct{}),
} }
} }
// Done returns true if Close() is called.
func (d *Done) Done() bool { func (d *Done) Done() bool {
select { select {
case <-d.c: 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{} { func (d *Done) C() chan struct{} {
return d.c return d.c
} }
// Wait blocks until Close() is called.
func (d *Done) Wait() { func (d *Done) Wait() {
<-d.c <-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 { func (d *Done) Close() error {
d.access.Lock() d.access.Lock()
defer d.access.Unlock() defer d.access.Unlock()

View File

@ -1,15 +1,18 @@
package signal 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 { type Notifier struct {
c chan struct{} c chan struct{}
} }
// NewNotifier creates a new Notifier.
func NewNotifier() *Notifier { func NewNotifier() *Notifier {
return &Notifier{ return &Notifier{
c: make(chan struct{}, 1), c: make(chan struct{}, 1),
} }
} }
// Signal signals a change, usually by producer. This method never blocks.
func (n *Notifier) Signal() { func (n *Notifier) Signal() {
select { select {
case n.c <- struct{}{}: 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{} { func (n *Notifier) Wait() <-chan struct{} {
return n.c return n.c
} }

View File

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

View File

@ -2,16 +2,23 @@ package all
import ( import (
// The following are necessary as they register handlers in their init functions. // 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/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/dns"
_ "v2ray.com/core/app/log" _ "v2ray.com/core/app/log"
_ "v2ray.com/core/app/policy" _ "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" _ "v2ray.com/core/app/router"
// Inbound and outbound proxies.
_ "v2ray.com/core/proxy/blackhole" _ "v2ray.com/core/proxy/blackhole"
_ "v2ray.com/core/proxy/dokodemo" _ "v2ray.com/core/proxy/dokodemo"
_ "v2ray.com/core/proxy/freedom" _ "v2ray.com/core/proxy/freedom"
@ -21,12 +28,14 @@ import (
_ "v2ray.com/core/proxy/vmess/inbound" _ "v2ray.com/core/proxy/vmess/inbound"
_ "v2ray.com/core/proxy/vmess/outbound" _ "v2ray.com/core/proxy/vmess/outbound"
// Transports
_ "v2ray.com/core/transport/internet/kcp" _ "v2ray.com/core/transport/internet/kcp"
_ "v2ray.com/core/transport/internet/tcp" _ "v2ray.com/core/transport/internet/tcp"
_ "v2ray.com/core/transport/internet/tls" _ "v2ray.com/core/transport/internet/tls"
_ "v2ray.com/core/transport/internet/udp" _ "v2ray.com/core/transport/internet/udp"
_ "v2ray.com/core/transport/internet/websocket" _ "v2ray.com/core/transport/internet/websocket"
// Transport headers
_ "v2ray.com/core/transport/internet/headers/http" _ "v2ray.com/core/transport/internet/headers/http"
_ "v2ray.com/core/transport/internet/headers/noop" _ "v2ray.com/core/transport/internet/headers/noop"
_ "v2ray.com/core/transport/internet/headers/srtp" _ "v2ray.com/core/transport/internet/headers/srtp"