Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-proxy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ygopro-proxy
Commits
bb7863da
Commit
bb7863da
authored
Oct 02, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tcpProxy
parent
6a6ce870
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
13 deletions
+22
-13
proxy.go
proxy.go
+22
-13
No files found.
proxy.go
View file @
bb7863da
package
main
import
(
"
bufio
"
"
encoding/binary
"
"io"
"log"
"net"
...
...
@@ -134,12 +134,10 @@ func wsProxy(ws *websocket.Conn, Ch chan<- []byte, stopCh <-chan bool, ctx util.
}
func
tcpProxy
(
tcp
net
.
Conn
,
Ch
chan
<-
[]
byte
,
stopCh
<-
chan
bool
,
ctx
util
.
Context
)
{
const
PACKET_LEN_PENDING
=
2
defer
tcp
.
Close
()
defer
close
(
Ch
)
reader
:=
bufio
.
NewReader
(
tcp
)
buffer
:=
make
([]
byte
,
BUFFER_SIZE
)
for
{
select
{
case
_
,
ok
:=
<-
stopCh
:
...
...
@@ -151,12 +149,8 @@ func tcpProxy(tcp net.Conn, Ch chan<- []byte, stopCh <-chan bool, ctx util.Conte
return
}
n
,
err
:=
reader
.
Read
(
buffer
)
if
err
!=
nil
{
if
err
==
io
.
EOF
{
continue
}
guardBuf
:=
make
([]
byte
,
PACKET_LEN_PENDING
)
if
_
,
err
:=
tcp
.
Read
(
guardBuf
);
err
!=
nil
{
if
err
,
ok
:=
err
.
(
net
.
Error
);
ok
&&
err
.
Timeout
()
{
continue
}
...
...
@@ -164,15 +158,30 @@ func tcpProxy(tcp net.Conn, Ch chan<- []byte, stopCh <-chan bool, ctx util.Conte
log
.
Println
(
err
)
return
}
ctx
.
InfaReadBufferLen
=
n
buffer
,
err
=
darkneos
.
Transform
(
buffer
,
darkneos
.
RawBufToProtobuf
,
&
ctx
)
packet_len
:=
int
(
binary
.
LittleEndian
.
Uint16
(
guardBuf
))
ctx
.
InfaReadBufferLen
=
PACKET_LEN_PENDING
buffer
:=
make
([]
byte
,
packet_len
+
PACKET_LEN_PENDING
)
copy
(
buffer
,
guardBuf
)
if
packet_len
>
0
{
n
,
err
:=
io
.
ReadAtLeast
(
tcp
,
buffer
[
PACKET_LEN_PENDING
:
],
packet_len
)
if
err
!=
nil
&&
err
!=
io
.
EOF
{
log
.
Println
(
err
)
return
}
ctx
.
InfaReadBufferLen
+=
n
}
newBuffer
,
err
:=
darkneos
.
Transform
(
buffer
,
darkneos
.
RawBufToProtobuf
,
&
ctx
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
}
Ch
<-
b
uffer
Ch
<-
newB
uffer
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment