Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
ffbe5656
Commit
ffbe5656
authored
Jun 25, 2015
by
Bas van Kervel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for large requests/responses
parent
6d92fdc0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
17 deletions
+32
-17
json.go
rpc/codec/json.go
+30
-16
ipc.go
rpc/comms/ipc.go
+1
-0
ipc_unix.go
rpc/comms/ipc_unix.go
+1
-1
No files found.
rpc/codec/json.go
View file @
ffbe5656
...
...
@@ -2,28 +2,30 @@ package codec
import
(
"encoding/json"
"fmt"
"net"
"time"
"github.com/ethereum/go-ethereum/rpc/shared"
)
const
(
MAX_REQUEST_SIZE
=
1024
*
1024
MAX_REQUEST_SIZE
=
1024
*
1024
MAX_RESPONSE_SIZE
=
1024
*
1024
)
// Json serialization support
type
JsonCodec
struct
{
c
net
.
Conn
buffer
[]
byte
c
net
.
Conn
buffer
[]
byte
bytesInBuffer
int
}
// Create new JSON coder instance
func
NewJsonCoder
(
conn
net
.
Conn
)
ApiCoder
{
return
&
JsonCodec
{
c
:
conn
,
buffer
:
make
([]
byte
,
MAX_REQUEST_SIZE
),
c
:
conn
,
buffer
:
make
([]
byte
,
MAX_REQUEST_SIZE
),
bytesInBuffer
:
0
,
}
}
...
...
@@ -58,28 +60,40 @@ func (self *JsonCodec) ReadRequest() (requests []*shared.Request, isBatch bool,
}
func
(
self
*
JsonCodec
)
ReadResponse
()
(
interface
{},
error
)
{
var
err
error
bytesInBuffer
:=
0
buf
:=
make
([]
byte
,
MAX_RESPONSE_SIZE
)
n
,
_
:=
self
.
c
.
Read
(
buf
)
var
failure
shared
.
ErrorResponse
if
err
=
json
.
Unmarshal
(
buf
[
:
n
],
&
failure
);
err
==
nil
&&
failure
.
Error
!=
nil
{
return
failure
,
nil
}
deadline
:=
time
.
Now
()
.
Add
(
15
*
time
.
Second
)
self
.
c
.
SetDeadline
(
deadline
)
for
{
n
,
err
:=
self
.
c
.
Read
(
buf
[
bytesInBuffer
:
])
if
err
!=
nil
{
return
nil
,
err
}
bytesInBuffer
+=
n
var
success
shared
.
SuccessResponse
if
err
=
json
.
Unmarshal
(
buf
[
:
n
],
&
success
);
err
==
nil
{
return
success
,
nil
var
success
shared
.
SuccessResponse
if
err
=
json
.
Unmarshal
(
buf
[
:
bytesInBuffer
],
&
success
);
err
==
nil
{
return
success
,
nil
}
var
failure
shared
.
ErrorResponse
if
err
=
json
.
Unmarshal
(
buf
[
:
bytesInBuffer
],
&
failure
);
err
==
nil
&&
failure
.
Error
!=
nil
{
return
failure
,
nil
}
}
return
nil
,
err
self
.
c
.
Close
()
return
nil
,
fmt
.
Errorf
(
"Unable to read response"
)
}
//
Encode response to encoded form in underlying stream
//
Decode data
func
(
self
*
JsonCodec
)
Decode
(
data
[]
byte
,
msg
interface
{})
error
{
return
json
.
Unmarshal
(
data
,
msg
)
}
// Encode message
func
(
self
*
JsonCodec
)
Encode
(
msg
interface
{})
([]
byte
,
error
)
{
return
json
.
Marshal
(
msg
)
}
...
...
rpc/comms/ipc.go
View file @
ffbe5656
...
...
@@ -16,6 +16,7 @@ type IpcConfig struct {
type
ipcClient
struct
{
endpoint
string
c
net
.
Conn
codec
codec
.
Codec
coder
codec
.
ApiCoder
}
...
...
rpc/comms/ipc_unix.go
View file @
ffbe5656
...
...
@@ -18,7 +18,7 @@ func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
return
nil
,
err
}
return
&
ipcClient
{
cfg
.
Endpoint
,
codec
,
codec
.
New
(
c
)},
nil
return
&
ipcClient
{
cfg
.
Endpoint
,
c
,
c
odec
,
codec
.
New
(
c
)},
nil
}
func
(
self
*
ipcClient
)
reconnect
()
error
{
...
...
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