Skip to content

Commit

Permalink
mv logs.go to fly package
Browse files Browse the repository at this point in the history
  • Loading branch information
asche910 committed Oct 18, 2019
1 parent 6911471 commit 0d54de2
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 29 deletions.
7 changes: 3 additions & 4 deletions cmd/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/asche910/flynet/client"
"github.com/asche910/flynet/fly"
"github.com/asche910/flynet/logs"
"log"
"os"
"strings"
Expand Down Expand Up @@ -133,10 +132,10 @@ func parseArgs(args []string) {
os.Exit(1)
}
case "--verbose", "-V":
logs.EnableDebug(true)
fly.EnableDebug(true)
parseArgs(args[1:])
case "--logs", "-l":
logs.EnableLog(true)
fly.EnableLog(true)
parseArgs(args[1:])
case "--help", "-H":
printHelp()
Expand Down Expand Up @@ -172,5 +171,5 @@ func checkArgs() {

func initLog() {
fly.InitLog()
logger = logs.GetLogger()
logger = fly.GetLogger()
}
8 changes: 2 additions & 6 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ package main
import (
"fmt"
"github.com/asche910/flynet/fly"
"github.com/asche910/flynet/logs"
"github.com/asche910/flynet/server"
"log"
"os"
"strings"
)

var (
logger *log.Logger
flyServer = server.FlyServer{}
MODE_MAP = map[int]string{1: "http", 2: "socks5", 3: "socks5-tcp", 4: "socks5-udp", 5: "forward"}
)
Expand Down Expand Up @@ -124,10 +121,10 @@ func parseArgs(args []string) {
os.Exit(1)
}
case "--verbose", "-V":
logs.EnableDebug(true)
fly.EnableDebug(true)
parseArgs(args[1:])
case "--logs", "-l":
logs.EnableLog(true)
fly.EnableLog(true)
parseArgs(args[1:])
case "--help", "-H":
printHelp()
Expand Down Expand Up @@ -162,5 +159,4 @@ func checkArgs() {

func initLog() {
fly.InitLog()
logger = logs.GetLogger()
}
5 changes: 5 additions & 0 deletions fly/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fly

type Config struct {

}
8 changes: 0 additions & 8 deletions fly/error_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@ package fly

import (
"fmt"
"github.com/asche910/flynet/logs"
"log"
)

var logger *log.Logger

func InitLog() {
logger = logs.GetLogger()
}

// just check error and print if err is not nil
func CheckError(err error, info string) {
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions fly/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func StartHttp(port string) {
continue
}
logger.Println("accept success!")
go handleClientRequest(client)
go handleHttpClient(client)
}
}

func handleClientRequest(client net.Conn) {
func handleHttpClient(client net.Conn) {
if client == nil {
return
}
Expand Down
9 changes: 6 additions & 3 deletions logs/logs.go → fly/logs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package logs
package fly

import (
"io"
Expand All @@ -9,9 +9,13 @@ import (
var (
logFlag = false
debugFlag = false
logger *log.Logger
logger *log.Logger
)

func InitLog() {
logger = GetLogger()
}

func EnableLog(flag bool) {
logFlag = flag
}
Expand Down Expand Up @@ -48,6 +52,5 @@ func GetLogger() *log.Logger {
targetWriter := io.MultiWriter(writers...)
// cancel log.Lshortfile
logs := log.New(targetWriter, "", log.Ldate|log.Ltime)
logger = logs
return logs
}
1 change: 0 additions & 1 deletion fly/pac.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fly

import (
"fmt"
"io"
"net/http"
"os"
Expand Down
6 changes: 4 additions & 2 deletions fly/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func StartSocks5(port string) {
}
logger.Println("client accepted!")

go handleClient(client)
go handleLocalClient(client)
}
}

func handleClient(client net.Conn) {
func handleLocalClient(client net.Conn) {
data := make([]byte, 1024)
n, err := client.Read(data[:])
if err != nil {
Expand Down Expand Up @@ -304,6 +304,8 @@ func handlePACRequest(conn net.Conn, buff []byte, port string) {
"Content-Type: application/x-ns-proxy-autoconfig\r\n"+
"Server: flynet\r\nContent-Length: %d\r\n\r\n", size)))
_, _ = conn.Write(fileBuff[:size])

logger.Printf("pac mode is on, the url is: http://localhost:%s/flynet.pac\n", port)
}else {
msg := "hello,flynet!"
_, _ = conn.Write([]byte(fmt.Sprintf("HTTP/1.1 200 OK\r\n"+
Expand Down
4 changes: 1 addition & 3 deletions flynet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ port = 1080 # local socks5 listen port
serverAddr = example.com:8888 # include host and port
method = aes-256-cfb
password =
pac-on = true # if true, flynet will start pac mode, and listen at 'http://localhost:pac-port/flynet.pac'(default pac-port is 2080)
pac-port = 2080
pac-update = false # if true, flynet will download the latest pac file from github
pac-on = true # if true, flynet will start pac mode, and listen at 'http://localhost:port/flynet.pac'(the port is the socks5 port)
verbose = false
# log = flynet.log

0 comments on commit 0d54de2

Please sign in to comment.