引入读json配置文件
This commit is contained in:
parent
97edfb5fff
commit
9a18b5323d
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"cacheSize":4096,
|
||||
"queueLength":10
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func init() {
|
||||
viper.SetConfigType("json")
|
||||
viper.SetConfigName("config")
|
||||
viper.AddConfigPath(".")
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
fmt.Println("faield to parse config file %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
// "fmt"
|
||||
"fmt"
|
||||
"github.com/TransX/log"
|
||||
"github.com/TransX/protocol"
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue