引入读json配置文件

This commit is contained in:
dmy@lab
2016-01-17 22:34:26 +08:00
parent 97edfb5fff
commit 9a18b5323d
4 changed files with 27 additions and 22 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/TransX/constant"
"github.com/TransX/log"
"github.com/TransX/tscipher"
"github.com/spf13/viper"
"net"
"time"
)
@@ -53,15 +54,15 @@ func (this *Tunnel) Run() { //单向的从src发送到dest
this.regChan <- this
src := this.src
dest := this.dest
// cipherDirection := this.cipherDirection
id := this.id
// cache := make([]byte, 1024*4) //4kB
//构建Carrier
queCache := cache.NewBlockingQueueCache(1)
for i := 0; i < 1; i++ {
queCache.Put(make([]byte, 1024*4), 0)
queLength := viper.GetInt("queueLength")
queCache := cache.NewBlockingQueueCache(queLength)
cacheSize := viper.GetInt("cacheSize")
for i := 0; i < queLength; i++ {
queCache.Put(make([]byte, cacheSize), 0)
}
msg := cache.NewBlockingQueueCache(1)
msg := cache.NewBlockingQueueCache(queLength)
revCarrier := tscipher.NewCarrier(src, tscipher.NewCipher("XOR"), queCache, msg, id)
sendCarrier := tscipher.NewCarrier(dest, tscipher.NewCipher("XOR"), queCache, msg, id)
go this.receive(revCarrier)
@@ -92,21 +93,6 @@ func (this *Tunnel) receive(revCarrier *tscipher.Carrier) {
cipherDirection := this.cipherDirection
id := this.id
defer this.onError()
// defer func() {
// //注销
// if !this.unregistered { // 应该不存在异步问题
// this.unregChan <- this
// this.unregistered = true
// }
// if r := recover(); r != nil {
// if src != nil {
// src.Close()
// }
// if dest != nil {
// dest.Close()
// }
// }
// }()
var n int
var err error
for {