good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
ce5c94e4
Commit
ce5c94e4
authored
Jun 19, 2015
by
Bas van Kervel
Browse files
Options
Downloads
Patches
Plain Diff
added attach over http/rpc support
parent
f2025637
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
rpc/comms/comms.go
+23
-0
23 additions, 0 deletions
rpc/comms/comms.go
rpc/comms/http.go
+109
-5
109 additions, 5 deletions
rpc/comms/http.go
rpc/comms/ipc.go
+2
-1
2 additions, 1 deletion
rpc/comms/ipc.go
with
134 additions
and
6 deletions
rpc/comms/comms.go
+
23
−
0
View file @
ce5c94e4
...
@@ -7,6 +7,8 @@ import (
...
@@ -7,6 +7,8 @@ import (
"fmt"
"fmt"
"strings"
"strings"
"strconv"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/api"
...
@@ -82,7 +84,28 @@ func ClientFromEndpoint(endpoint string, c codec.Codec) (EthereumClient, error)
...
@@ -82,7 +84,28 @@ func ClientFromEndpoint(endpoint string, c codec.Codec) (EthereumClient, error)
}
}
if
strings
.
HasPrefix
(
endpoint
,
"rpc:"
)
{
if
strings
.
HasPrefix
(
endpoint
,
"rpc:"
)
{
parts
:=
strings
.
Split
(
endpoint
,
":"
)
addr
:=
"http://localhost"
port
:=
uint
(
8545
)
if
len
(
parts
)
>=
3
{
addr
=
parts
[
1
]
+
":"
+
parts
[
2
]
}
if
len
(
parts
)
>=
4
{
p
,
err
:=
strconv
.
Atoi
(
parts
[
3
])
if
err
!=
nil
{
return
nil
,
err
}
port
=
uint
(
p
)
}
cfg
:=
HttpConfig
{
ListenAddress
:
addr
,
ListenPort
:
port
,
}
return
NewHttpClient
(
cfg
,
codec
.
JSON
),
nil
}
}
return
nil
,
fmt
.
Errorf
(
"Invalid endpoint"
)
return
nil
,
fmt
.
Errorf
(
"Invalid endpoint"
)
...
...
This diff is collapsed.
Click to expand it.
rpc/comms/http.go
+
109
−
5
View file @
ce5c94e4
...
@@ -5,10 +5,14 @@ import (
...
@@ -5,10 +5,14 @@ import (
"net/http"
"net/http"
"strings"
"strings"
"bytes"
"io/ioutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/rs/cors"
"github.com/rs/cors"
)
)
...
@@ -65,13 +69,19 @@ func StopHttp() {
...
@@ -65,13 +69,19 @@ func StopHttp() {
}
}
type
httpClient
struct
{
type
httpClient
struct
{
address
string
port
uint
codec
codec
.
ApiCoder
codec
codec
.
ApiCoder
lastRes
interface
{}
lastErr
error
}
}
// Create a new in process client
// Create a new in process client
func
NewHttpClient
(
cfg
HttpConfig
,
c
odec
codec
.
Codec
)
*
httpClient
{
func
NewHttpClient
(
cfg
HttpConfig
,
c
codec
.
Codec
)
*
httpClient
{
return
&
httpClient
{
return
&
httpClient
{
codec
:
codec
.
New
(
nil
),
address
:
cfg
.
ListenAddress
,
port
:
cfg
.
ListenPort
,
codec
:
c
.
New
(
nil
),
}
}
}
}
...
@@ -80,9 +90,103 @@ func (self *httpClient) Close() {
...
@@ -80,9 +90,103 @@ func (self *httpClient) Close() {
}
}
func
(
self
*
httpClient
)
Send
(
req
interface
{})
error
{
func
(
self
*
httpClient
)
Send
(
req
interface
{})
error
{
var
body
[]
byte
var
err
error
self
.
lastRes
=
nil
self
.
lastErr
=
nil
if
body
,
err
=
self
.
codec
.
Encode
(
req
);
err
!=
nil
{
return
err
}
httpReq
,
err
:=
http
.
NewRequest
(
"POST"
,
fmt
.
Sprintf
(
"%s:%d"
,
self
.
address
,
self
.
port
),
bytes
.
NewBuffer
(
body
))
if
err
!=
nil
{
return
err
}
httpReq
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
client
:=
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
httpReq
)
if
err
!=
nil
{
return
err
}
defer
resp
.
Body
.
Close
()
if
resp
.
Status
==
"200 OK"
{
reply
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
var
rpcSuccessResponse
shared
.
SuccessResponse
if
err
=
self
.
codec
.
Decode
(
reply
,
&
rpcSuccessResponse
);
err
==
nil
{
self
.
lastRes
=
rpcSuccessResponse
.
Result
self
.
lastErr
=
err
return
nil
}
else
{
var
rpcErrorResponse
shared
.
ErrorResponse
if
err
=
self
.
codec
.
Decode
(
reply
,
&
rpcErrorResponse
);
err
==
nil
{
self
.
lastRes
=
rpcErrorResponse
.
Error
self
.
lastErr
=
err
return
nil
return
nil
}
else
{
return
err
}
}
}
return
fmt
.
Errorf
(
"Not implemented"
)
}
}
func
(
self
*
httpClient
)
Recv
()
(
interface
{},
error
)
{
func
(
self
*
httpClient
)
Recv
()
(
interface
{},
error
)
{
return
nil
,
nil
return
self
.
lastRes
,
self
.
lastErr
}
func
(
self
*
httpClient
)
SupportedModules
()
(
map
[
string
]
string
,
error
)
{
var
body
[]
byte
var
err
error
payload
:=
shared
.
Request
{
Id
:
1
,
Jsonrpc
:
"2.0"
,
Method
:
"modules"
,
}
if
body
,
err
=
self
.
codec
.
Encode
(
payload
);
err
!=
nil
{
return
nil
,
err
}
req
,
err
:=
http
.
NewRequest
(
"POST"
,
fmt
.
Sprintf
(
"%s:%d"
,
self
.
address
,
self
.
port
),
bytes
.
NewBuffer
(
body
))
if
err
!=
nil
{
return
nil
,
err
}
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
client
:=
http
.
Client
{}
resp
,
err
:=
client
.
Do
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
defer
resp
.
Body
.
Close
()
if
resp
.
Status
==
"200 OK"
{
reply
,
_
:=
ioutil
.
ReadAll
(
resp
.
Body
)
var
rpcRes
shared
.
SuccessResponse
if
err
=
self
.
codec
.
Decode
(
reply
,
&
rpcRes
);
err
!=
nil
{
return
nil
,
err
}
result
:=
make
(
map
[
string
]
string
)
if
modules
,
ok
:=
rpcRes
.
Result
.
(
map
[
string
]
interface
{});
ok
{
for
a
,
v
:=
range
modules
{
result
[
a
]
=
fmt
.
Sprintf
(
"%s"
,
v
)
}
return
result
,
nil
}
err
=
fmt
.
Errorf
(
"Unable to parse module response - %v"
,
rpcRes
.
Result
)
}
else
{
fmt
.
Printf
(
"resp.Status = %s
\n
"
,
resp
.
Status
)
fmt
.
Printf
(
"err = %v
\n
"
,
err
)
}
return
nil
,
err
}
}
This diff is collapsed.
Click to expand it.
rpc/comms/ipc.go
+
2
−
1
View file @
ce5c94e4
...
@@ -4,10 +4,11 @@ import (
...
@@ -4,10 +4,11 @@ import (
"fmt"
"fmt"
"net"
"net"
"encoding/json"
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/shared"
"encoding/json"
)
)
type
IpcConfig
struct
{
type
IpcConfig
struct
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment