Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
企猫商务
frp
提交
50165053
F
frp
项目概览
企猫商务
/
frp
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
frp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
50165053
编写于
2月 18, 2016
作者:
F
fatedier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change directory structure, move models and utils to root directory
上级
30da2a2d
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
76 addition
and
67 deletion
+76
-67
cmd/frpc/config.go
cmd/frpc/config.go
+3
-4
cmd/frpc/control.go
cmd/frpc/control.go
+10
-8
cmd/frpc/main.go
cmd/frpc/main.go
+1
-1
cmd/frps/config.go
cmd/frps/config.go
+3
-3
cmd/frps/control.go
cmd/frps/control.go
+27
-24
cmd/frps/main.go
cmd/frps/main.go
+2
-2
models/client/client.go
models/client/client.go
+7
-5
models/consts/consts.go
models/consts/consts.go
+13
-0
models/msg/msg.go
models/msg/msg.go
+1
-7
models/server/server.go
models/server/server.go
+8
-12
utils/conn/conn.go
utils/conn/conn.go
+1
-1
utils/log/log.go
utils/log/log.go
+0
-0
utils/pcrypto/pcrypto.go
utils/pcrypto/pcrypto.go
+0
-0
utils/pcrypto/pcrypto_test.go
utils/pcrypto/pcrypto_test.go
+0
-0
未找到文件。
cmd/frpc/config.go
浏览文件 @
50165053
...
...
@@ -4,8 +4,7 @@ import (
"fmt"
"strconv"
"github.com/fatedier/frp/pkg/models"
"github.com/fatedier/frp/models/client"
ini
"github.com/vaughan0/go-ini"
)
...
...
@@ -19,7 +18,7 @@ var (
HeartBeatInterval
int64
=
5
)
var
ProxyClients
map
[
string
]
*
models
.
ProxyClient
=
make
(
map
[
string
]
*
models
.
ProxyClient
)
var
ProxyClients
map
[
string
]
*
client
.
ProxyClient
=
make
(
map
[
string
]
*
client
.
ProxyClient
)
func
LoadConf
(
confFile
string
)
(
err
error
)
{
var
tmpStr
string
...
...
@@ -59,7 +58,7 @@ func LoadConf(confFile string) (err error) {
// servers
for
name
,
section
:=
range
conf
{
if
name
!=
"common"
{
proxyClient
:=
&
models
.
ProxyClient
{}
proxyClient
:=
&
client
.
ProxyClient
{}
proxyClient
.
Name
=
name
proxyClient
.
Passwd
,
ok
=
section
[
"passwd"
]
...
...
cmd/frpc/control.go
浏览文件 @
50165053
...
...
@@ -6,14 +6,16 @@ import (
"sync"
"time"
"github.com/fatedier/frp/pkg/models"
"github.com/fatedier/frp/pkg/utils/conn"
"github.com/fatedier/frp/pkg/utils/log"
"github.com/fatedier/frp/models/client"
"github.com/fatedier/frp/models/consts"
"github.com/fatedier/frp/models/msg"
"github.com/fatedier/frp/utils/conn"
"github.com/fatedier/frp/utils/log"
)
var
isHeartBeatContinue
bool
=
true
func
ControlProcess
(
cli
*
models
.
ProxyClient
,
wait
*
sync
.
WaitGroup
)
{
func
ControlProcess
(
cli
*
client
.
ProxyClient
,
wait
*
sync
.
WaitGroup
)
{
defer
wait
.
Done
()
c
:=
loginToServer
(
cli
)
...
...
@@ -54,7 +56,7 @@ func ControlProcess(cli *models.ProxyClient, wait *sync.WaitGroup) {
}
}
func
loginToServer
(
cli
*
models
.
ProxyClient
)
(
connection
*
conn
.
Conn
)
{
func
loginToServer
(
cli
*
client
.
ProxyClient
)
(
connection
*
conn
.
Conn
)
{
c
:=
&
conn
.
Conn
{}
connection
=
nil
...
...
@@ -65,8 +67,8 @@ func loginToServer(cli *models.ProxyClient) (connection *conn.Conn) {
break
}
req
:=
&
m
odels
.
ClientCtlReq
{
Type
:
models
.
Contro
lConn
,
req
:=
&
m
sg
.
ClientCtlReq
{
Type
:
consts
.
Ct
lConn
,
ProxyName
:
cli
.
Name
,
Passwd
:
cli
.
Passwd
,
}
...
...
@@ -84,7 +86,7 @@ func loginToServer(cli *models.ProxyClient) (connection *conn.Conn) {
}
log
.
Debug
(
"ProxyName [%s], read [%s]"
,
cli
.
Name
,
res
)
clientCtlRes
:=
&
m
odels
.
ClientCtlRes
{}
clientCtlRes
:=
&
m
sg
.
ClientCtlRes
{}
if
err
=
json
.
Unmarshal
([]
byte
(
res
),
&
clientCtlRes
);
err
!=
nil
{
log
.
Error
(
"ProxyName [%s], format server response error, %v"
,
cli
.
Name
,
err
)
break
...
...
cmd/frpc/main.go
浏览文件 @
50165053
...
...
@@ -4,7 +4,7 @@ import (
"os"
"sync"
"github.com/fatedier/frp/
pkg/
utils/log"
"github.com/fatedier/frp/utils/log"
)
func
main
()
{
...
...
cmd/frps/config.go
浏览文件 @
50165053
...
...
@@ -4,7 +4,7 @@ import (
"fmt"
"strconv"
"github.com/fatedier/frp/
pkg/models
"
"github.com/fatedier/frp/
models/server
"
ini
"github.com/vaughan0/go-ini"
)
...
...
@@ -19,7 +19,7 @@ var (
HeartBeatTimeout
int64
=
30
)
var
ProxyServers
map
[
string
]
*
models
.
ProxyServer
=
make
(
map
[
string
]
*
models
.
ProxyServer
)
var
ProxyServers
map
[
string
]
*
server
.
ProxyServer
=
make
(
map
[
string
]
*
server
.
ProxyServer
)
func
LoadConf
(
confFile
string
)
(
err
error
)
{
var
tmpStr
string
...
...
@@ -59,7 +59,7 @@ func LoadConf(confFile string) (err error) {
// servers
for
name
,
section
:=
range
conf
{
if
name
!=
"common"
{
proxyServer
:=
&
models
.
ProxyServer
{}
proxyServer
:=
&
server
.
ProxyServer
{}
proxyServer
.
Name
=
name
proxyServer
.
Passwd
,
ok
=
section
[
"passwd"
]
...
...
cmd/frps/control.go
浏览文件 @
50165053
...
...
@@ -6,9 +6,11 @@ import (
"io"
"time"
"github.com/fatedier/frp/pkg/models"
"github.com/fatedier/frp/pkg/utils/conn"
"github.com/fatedier/frp/pkg/utils/log"
"github.com/fatedier/frp/models/consts"
"github.com/fatedier/frp/models/msg"
"github.com/fatedier/frp/models/server"
"github.com/fatedier/frp/utils/conn"
"github.com/fatedier/frp/utils/log"
)
func
ProcessControlConn
(
l
*
conn
.
Listener
)
{
...
...
@@ -30,18 +32,18 @@ func controlWorker(c *conn.Conn) {
}
log
.
Debug
(
"get: %s"
,
res
)
clientCtlReq
:=
&
m
odels
.
ClientCtlReq
{}
clientCtlRes
:=
&
m
odels
.
ClientCtlRes
{}
clientCtlReq
:=
&
m
sg
.
ClientCtlReq
{}
clientCtlRes
:=
&
m
sg
.
ClientCtlRes
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
res
),
&
clientCtlReq
);
err
!=
nil
{
log
.
Warn
(
"Parse err: %v : %s"
,
err
,
res
)
return
}
// check
succ
,
msg
,
needRes
:=
checkProxy
(
clientCtlReq
,
c
)
succ
,
info
,
needRes
:=
checkProxy
(
clientCtlReq
,
c
)
if
!
succ
{
clientCtlRes
.
Code
=
1
clientCtlRes
.
Msg
=
msg
clientCtlRes
.
Msg
=
info
}
if
needRes
{
...
...
@@ -70,8 +72,8 @@ func controlWorker(c *conn.Conn) {
// read control msg from client
go
readControlMsgFromClient
(
server
,
c
)
serverCtlReq
:=
&
m
odels
.
ClientCtlReq
{}
serverCtlReq
.
Type
=
model
s
.
WorkConn
serverCtlReq
:=
&
m
sg
.
ClientCtlReq
{}
serverCtlReq
.
Type
=
const
s
.
WorkConn
for
{
_
,
isStop
:=
server
.
WaitUserConn
()
if
isStop
{
...
...
@@ -92,52 +94,53 @@ func controlWorker(c *conn.Conn) {
return
}
func
checkProxy
(
req
*
m
odels
.
ClientCtlReq
,
c
*
conn
.
Conn
)
(
succ
bool
,
msg
string
,
needRes
bool
)
{
func
checkProxy
(
req
*
m
sg
.
ClientCtlReq
,
c
*
conn
.
Conn
)
(
succ
bool
,
info
string
,
needRes
bool
)
{
succ
=
false
needRes
=
true
// check if proxy name exist
server
,
ok
:=
ProxyServers
[
req
.
ProxyName
]
if
!
ok
{
msg
=
fmt
.
Sprintf
(
"ProxyName [%s] is not exist"
,
req
.
ProxyName
)
log
.
Warn
(
msg
)
info
=
fmt
.
Sprintf
(
"ProxyName [%s] is not exist"
,
req
.
ProxyName
)
log
.
Warn
(
info
)
return
}
// check password
if
req
.
Passwd
!=
server
.
Passwd
{
msg
=
fmt
.
Sprintf
(
"ProxyName [%s], password is not correct"
,
req
.
ProxyName
)
log
.
Warn
(
msg
)
info
=
fmt
.
Sprintf
(
"ProxyName [%s], password is not correct"
,
req
.
ProxyName
)
log
.
Warn
(
info
)
return
}
// control conn
if
req
.
Type
==
models
.
Contro
lConn
{
if
server
.
Status
!=
model
s
.
Idle
{
msg
=
fmt
.
Sprintf
(
"ProxyName [%s], already in use"
,
req
.
ProxyName
)
log
.
Warn
(
msg
)
if
req
.
Type
==
consts
.
Ct
lConn
{
if
server
.
Status
!=
const
s
.
Idle
{
info
=
fmt
.
Sprintf
(
"ProxyName [%s], already in use"
,
req
.
ProxyName
)
log
.
Warn
(
info
)
return
}
// start proxy and listen for user conn, no block
err
:=
server
.
Start
()
if
err
!=
nil
{
msg
=
fmt
.
Sprintf
(
"ProxyName [%s], start proxy error: %v"
,
req
.
ProxyName
,
err
.
Error
())
log
.
Warn
(
msg
)
info
=
fmt
.
Sprintf
(
"ProxyName [%s], start proxy error: %v"
,
req
.
ProxyName
,
err
.
Error
())
log
.
Warn
(
info
)
return
}
log
.
Info
(
"ProxyName [%s], start proxy success"
,
req
.
ProxyName
)
}
else
if
req
.
Type
==
model
s
.
WorkConn
{
}
else
if
req
.
Type
==
const
s
.
WorkConn
{
// work conn
needRes
=
false
if
server
.
Status
!=
model
s
.
Working
{
if
server
.
Status
!=
const
s
.
Working
{
log
.
Warn
(
"ProxyName [%s], is not working when it gets one new work conn"
,
req
.
ProxyName
)
return
}
server
.
CliConnChan
<-
c
}
else
{
log
.
Warn
(
"ProxyName [%s], type [%d] unsupport"
,
req
.
ProxyName
,
req
.
Type
)
info
=
fmt
.
Sprintf
(
"ProxyName [%s], type [%d] unsupport"
,
req
.
ProxyName
,
req
.
Type
)
log
.
Warn
(
info
)
return
}
...
...
@@ -145,7 +148,7 @@ func checkProxy(req *models.ClientCtlReq, c *conn.Conn) (succ bool, msg string,
return
}
func
readControlMsgFromClient
(
server
*
models
.
ProxyServer
,
c
*
conn
.
Conn
)
{
func
readControlMsgFromClient
(
server
*
server
.
ProxyServer
,
c
*
conn
.
Conn
)
{
isContinueRead
:=
true
f
:=
func
()
{
isContinueRead
=
false
...
...
cmd/frps/main.go
浏览文件 @
50165053
...
...
@@ -3,8 +3,8 @@ package main
import
(
"os"
"github.com/fatedier/frp/
pkg/
utils/conn"
"github.com/fatedier/frp/
pkg/
utils/log"
"github.com/fatedier/frp/utils/conn"
"github.com/fatedier/frp/utils/log"
)
func
main
()
{
...
...
pkg/models
/client.go
→
models/client
/client.go
浏览文件 @
50165053
package
models
package
client
import
(
"encoding/json"
"github.com/fatedier/frp/pkg/utils/conn"
"github.com/fatedier/frp/pkg/utils/log"
"github.com/fatedier/frp/models/consts"
"github.com/fatedier/frp/models/msg"
"github.com/fatedier/frp/utils/conn"
"github.com/fatedier/frp/utils/log"
)
type
ProxyClient
struct
{
...
...
@@ -36,8 +38,8 @@ func (p *ProxyClient) GetRemoteConn(addr string, port int64) (c *conn.Conn, err
return
}
req
:=
&
ClientCtlReq
{
Type
:
WorkConn
,
req
:=
&
msg
.
ClientCtlReq
{
Type
:
consts
.
WorkConn
,
ProxyName
:
p
.
Name
,
Passwd
:
p
.
Passwd
,
}
...
...
models/consts/consts.go
0 → 100644
浏览文件 @
50165053
package
consts
// server status
const
(
Idle
=
iota
Working
)
// connection type
const
(
CtlConn
=
iota
WorkConn
)
pkg/models
/msg.go
→
models/msg
/msg.go
浏览文件 @
50165053
package
m
odels
package
m
sg
type
GeneralRes
struct
{
Code
int64
`json:"code"`
Msg
string
`json:"msg"`
}
// type
const
(
ControlConn
=
iota
WorkConn
)
type
ClientCtlReq
struct
{
Type
int64
`json:"type"`
ProxyName
string
`json:"proxy_name"`
...
...
pkg/models
/server.go
→
models/server
/server.go
浏览文件 @
50165053
package
models
package
server
import
(
"container/list"
"sync"
"github.com/fatedier/frp/pkg/utils/conn"
"github.com/fatedier/frp/pkg/utils/log"
)
const
(
Idle
=
iota
Working
"github.com/fatedier/frp/models/consts"
"github.com/fatedier/frp/utils/conn"
"github.com/fatedier/frp/utils/log"
)
type
ProxyServer
struct
{
...
...
@@ -29,7 +25,7 @@ type ProxyServer struct {
}
func
(
p
*
ProxyServer
)
Init
()
{
p
.
Status
=
Idle
p
.
Status
=
consts
.
Idle
p
.
CtlMsgChan
=
make
(
chan
int64
)
p
.
StopBlockChan
=
make
(
chan
int64
)
p
.
CliConnChan
=
make
(
chan
*
conn
.
Conn
)
...
...
@@ -51,7 +47,7 @@ func (p *ProxyServer) Start() (err error) {
return
err
}
p
.
Status
=
Working
p
.
Status
=
consts
.
Working
// start a goroutine for listener
go
func
()
{
...
...
@@ -62,7 +58,7 @@ func (p *ProxyServer) Start() (err error) {
// put to list
p
.
Lock
()
if
p
.
Status
!=
Working
{
if
p
.
Status
!=
consts
.
Working
{
log
.
Debug
(
"ProxyName [%s] is not working, new user conn close"
,
p
.
Name
)
c
.
Close
()
p
.
Unlock
()
...
...
@@ -107,7 +103,7 @@ func (p *ProxyServer) Start() (err error) {
func
(
p
*
ProxyServer
)
Close
()
{
p
.
Lock
()
p
.
Status
=
Idle
p
.
Status
=
consts
.
Idle
p
.
CtlMsgChan
=
make
(
chan
int64
)
p
.
CliConnChan
=
make
(
chan
*
conn
.
Conn
)
p
.
UserConnList
=
list
.
New
()
...
...
pkg/
utils/conn/conn.go
→
utils/conn/conn.go
浏览文件 @
50165053
...
...
@@ -7,7 +7,7 @@ import (
"net"
"sync"
"github.com/fatedier/frp/
pkg/
utils/log"
"github.com/fatedier/frp/utils/log"
)
type
Listener
struct
{
...
...
pkg/
utils/log/log.go
→
utils/log/log.go
浏览文件 @
50165053
文件已移动
pkg/
utils/pcrypto/pcrypto.go
→
utils/pcrypto/pcrypto.go
浏览文件 @
50165053
文件已移动
pkg/
utils/pcrypto/pcrypto_test.go
→
utils/pcrypto/pcrypto_test.go
浏览文件 @
50165053
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录