Skip to content

Commit

Permalink
feat: using eventbus for traffic statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
若尘(樱の泪) committed Jan 18, 2019
1 parent fc645ce commit a141945
Show file tree
Hide file tree
Showing 20 changed files with 948 additions and 242 deletions.
9 changes: 9 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
# go-tests = true
# unused-packages = true


[[constraint]]
branch = "master"
name = "github.com/aead/chacha20"

[[constraint]]
branch = "master"
name = "golang.org/x/crypto"
Expand All @@ -48,3 +43,7 @@
[[constraint]]
name = "github.com/AlecAivazis/survey"
version = "1.8.0"

[[constraint]]
branch = "master"
name = "github.com/asaskevich/EventBus"
9 changes: 6 additions & 3 deletions cmd/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"fmt"
)

func main() {
s := "a,c,b,"
fmt.Printf(s[:len(s)-1])
type Test struct {
Name string
}

func main() {
a := Test{}
fmt.Print(a.(type))
}
17 changes: 17 additions & 0 deletions comm/eventbus/eventbus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package eventbus

import (
evbus "github.com/asaskevich/EventBus"
"github.com/rc452860/vnet/utils"
)

var eventBus evbus.Bus

func GetEventBus() evbus.Bus {
utils.Lock("eventbus:eventBus")
defer utils.UnLock("eventbus:eventBus")
if eventBus != nil {
eventBus = evbus.New()
}
return eventBus
}
9 changes: 0 additions & 9 deletions conn/common.go

This file was deleted.

3 changes: 2 additions & 1 deletion conn/conn_decorate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"time"

"github.com/rc452860/vnet/log"
"github.com/rc452860/vnet/pool"
"github.com/rc452860/vnet/utils"
"golang.org/x/time/rate"
Expand All @@ -26,7 +27,7 @@ func DialTcp(addr string) (IConn, error) {
}
err = con.(*net.TCPConn).SetKeepAlivePeriod(30 * time.Second)
if err != nil {
logging.Error("set tcp keepalive error: %v", err)
log.Error("set tcp keepalive error: %v", err)
}
return icon, nil
}
Expand Down
168 changes: 0 additions & 168 deletions conn/listener_decorate.go

This file was deleted.

8 changes: 5 additions & 3 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ func DbStarted(ctx context.Context) {
}

type DBTraffic struct {
Port int
Up uint64
Down uint64
Port int
Up uint64
Down uint64
ConnectCount int
Connects map[string]bool
}

var trafficTable = make(map[int]*DBTraffic)
Expand Down
5 changes: 4 additions & 1 deletion doc/开发须知.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ golang 语言学习网址: http://docscn.studygolang.com/
golang 标准库: https://studygolang.com/pkgdoc

## 依赖管理
dep
dep ensure


## EventBus
Loading

0 comments on commit a141945

Please sign in to comment.