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
982f73fa
Commit
982f73fa
authored
Feb 20, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added timeout for filter & removed clipboard. Closes #350
parent
00065853
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
129 additions
and
82 deletions
+129
-82
packages.go
rpc/packages.go
+59
-13
packages_test.go
rpc/packages_test.go
+37
-0
util.go
rpc/util.go
+33
-0
capi.hpp
ui/qt/clipboard/capi.hpp
+0
-11
clipboard.cpp
ui/qt/clipboard/clipboard.cpp
+0
-20
clipboard.go
ui/qt/clipboard/clipboard.go
+0
-15
clipboard.hpp
ui/qt/clipboard/clipboard.hpp
+0
-23
No files found.
rpc/packages.go
View file @
982f73fa
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"math/big"
"math/big"
"strings"
"strings"
"sync"
"sync"
"time"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
...
@@ -31,13 +32,14 @@ const (
...
@@ -31,13 +32,14 @@ const (
type
EthereumApi
struct
{
type
EthereumApi
struct
{
xeth
*
xeth
.
XEth
xeth
*
xeth
.
XEth
quit
chan
struct
{}
filterManager
*
filter
.
FilterManager
filterManager
*
filter
.
FilterManager
logMut
sync
.
RWMutex
logMut
sync
.
RWMutex
logs
map
[
int
]
state
.
Logs
logs
map
[
int
]
*
logFilter
messagesMut
sync
.
RWMutex
messagesMut
sync
.
RWMutex
messages
map
[
int
]
[]
xeth
.
WhisperMessage
messages
map
[
int
]
*
whisperFilter
// Register keeps a list of accounts and transaction data
// Register keeps a list of accounts and transaction data
regmut
sync
.
Mutex
regmut
sync
.
Mutex
register
map
[
string
][]
*
NewTxArgs
register
map
[
string
][]
*
NewTxArgs
...
@@ -49,12 +51,14 @@ func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
...
@@ -49,12 +51,14 @@ func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
db
,
_
:=
ethdb
.
NewLDBDatabase
(
"dapps"
)
db
,
_
:=
ethdb
.
NewLDBDatabase
(
"dapps"
)
api
:=
&
EthereumApi
{
api
:=
&
EthereumApi
{
xeth
:
eth
,
xeth
:
eth
,
quit
:
make
(
chan
struct
{}),
filterManager
:
filter
.
NewFilterManager
(
eth
.
Backend
()
.
EventMux
()),
filterManager
:
filter
.
NewFilterManager
(
eth
.
Backend
()
.
EventMux
()),
logs
:
make
(
map
[
int
]
state
.
Logs
),
logs
:
make
(
map
[
int
]
*
logFilter
),
messages
:
make
(
map
[
int
]
[]
xeth
.
WhisperMessage
),
messages
:
make
(
map
[
int
]
*
whisperFilter
),
db
:
db
,
db
:
db
,
}
}
go
api
.
filterManager
.
Start
()
go
api
.
filterManager
.
Start
()
go
api
.
start
()
return
api
return
api
}
}
...
@@ -97,7 +101,11 @@ func (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) erro
...
@@ -97,7 +101,11 @@ func (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) erro
self
.
logMut
.
Lock
()
self
.
logMut
.
Lock
()
defer
self
.
logMut
.
Unlock
()
defer
self
.
logMut
.
Unlock
()
self
.
logs
[
id
]
=
append
(
self
.
logs
[
id
],
logs
...
)
if
self
.
logs
[
id
]
==
nil
{
self
.
logs
[
id
]
=
&
logFilter
{
timeout
:
time
.
Now
()}
}
self
.
logs
[
id
]
.
add
(
logs
...
)
}
}
id
=
self
.
filterManager
.
InstallFilter
(
filter
)
id
=
self
.
filterManager
.
InstallFilter
(
filter
)
*
reply
=
id
*
reply
=
id
...
@@ -113,7 +121,11 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error
...
@@ -113,7 +121,11 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error
self
.
logMut
.
Lock
()
self
.
logMut
.
Lock
()
defer
self
.
logMut
.
Unlock
()
defer
self
.
logMut
.
Unlock
()
self
.
logs
[
id
]
=
append
(
self
.
logs
[
id
],
&
state
.
StateLog
{})
if
self
.
logs
[
id
]
==
nil
{
self
.
logs
[
id
]
=
&
logFilter
{
timeout
:
time
.
Now
()}
}
self
.
logs
[
id
]
.
add
(
&
state
.
StateLog
{})
}
}
if
args
==
"pending"
{
if
args
==
"pending"
{
filter
.
PendingCallback
=
callback
filter
.
PendingCallback
=
callback
...
@@ -131,9 +143,9 @@ func (self *EthereumApi) FilterChanged(id int, reply *interface{}) error {
...
@@ -131,9 +143,9 @@ func (self *EthereumApi) FilterChanged(id int, reply *interface{}) error {
self
.
logMut
.
Lock
()
self
.
logMut
.
Lock
()
defer
self
.
logMut
.
Unlock
()
defer
self
.
logMut
.
Unlock
()
*
reply
=
toLogs
(
self
.
logs
[
id
])
if
self
.
logs
[
id
]
!=
nil
{
*
reply
=
toLogs
(
self
.
logs
[
id
]
.
get
())
self
.
logs
[
id
]
=
nil
// empty the logs
}
return
nil
return
nil
}
}
...
@@ -331,7 +343,10 @@ func (p *EthereumApi) NewWhisperFilter(args *xeth.Options, reply *interface{}) e
...
@@ -331,7 +343,10 @@ func (p *EthereumApi) NewWhisperFilter(args *xeth.Options, reply *interface{}) e
args
.
Fn
=
func
(
msg
xeth
.
WhisperMessage
)
{
args
.
Fn
=
func
(
msg
xeth
.
WhisperMessage
)
{
p
.
messagesMut
.
Lock
()
p
.
messagesMut
.
Lock
()
defer
p
.
messagesMut
.
Unlock
()
defer
p
.
messagesMut
.
Unlock
()
p
.
messages
[
id
]
=
append
(
p
.
messages
[
id
],
msg
)
if
p
.
messages
[
id
]
==
nil
{
p
.
messages
[
id
]
=
&
whisperFilter
{
timeout
:
time
.
Now
()}
}
p
.
messages
[
id
]
.
add
(
msg
)
// = append(p.messages[id], msg)
}
}
id
=
p
.
xeth
.
Whisper
()
.
Watch
(
args
)
id
=
p
.
xeth
.
Whisper
()
.
Watch
(
args
)
*
reply
=
id
*
reply
=
id
...
@@ -342,9 +357,9 @@ func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error {
...
@@ -342,9 +357,9 @@ func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error {
self
.
messagesMut
.
Lock
()
self
.
messagesMut
.
Lock
()
defer
self
.
messagesMut
.
Unlock
()
defer
self
.
messagesMut
.
Unlock
()
*
reply
=
self
.
messages
[
id
]
if
self
.
messages
[
id
]
!=
nil
{
*
reply
=
self
.
messages
[
id
]
.
get
()
self
.
messages
[
id
]
=
nil
// empty the messages
}
return
nil
return
nil
}
}
...
@@ -535,3 +550,34 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
...
@@ -535,3 +550,34 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
rpclogger
.
DebugDetailf
(
"Reply: %T %s"
,
reply
,
reply
)
rpclogger
.
DebugDetailf
(
"Reply: %T %s"
,
reply
,
reply
)
return
nil
return
nil
}
}
var
filterTickerTime
=
15
*
time
.
Second
func
(
self
*
EthereumApi
)
start
()
{
timer
:=
time
.
NewTicker
(
filterTickerTime
)
done
:
for
{
select
{
case
<-
timer
.
C
:
self
.
logMut
.
Lock
()
self
.
messagesMut
.
Lock
()
for
id
,
filter
:=
range
self
.
logs
{
if
time
.
Since
(
filter
.
timeout
)
>
20
*
time
.
Second
{
delete
(
self
.
logs
,
id
)
}
}
for
id
,
filter
:=
range
self
.
messages
{
if
time
.
Since
(
filter
.
timeout
)
>
20
*
time
.
Second
{
delete
(
self
.
messages
,
id
)
}
}
case
<-
self
.
quit
:
break
done
}
}
}
func
(
self
*
EthereumApi
)
stop
()
{
close
(
self
.
quit
)
}
rpc/packages_test.go
0 → 100644
View file @
982f73fa
package
rpc
import
(
"sync"
"testing"
"time"
)
func
TestFilterClose
(
t
*
testing
.
T
)
{
api
:=
&
EthereumApi
{
logs
:
make
(
map
[
int
]
*
logFilter
),
messages
:
make
(
map
[
int
]
*
whisperFilter
),
quit
:
make
(
chan
struct
{}),
}
filterTickerTime
=
1
api
.
logs
[
0
]
=
&
logFilter
{}
api
.
messages
[
0
]
=
&
whisperFilter
{}
var
wg
sync
.
WaitGroup
wg
.
Add
(
1
)
go
api
.
start
()
go
func
()
{
select
{
case
<-
time
.
After
(
500
*
time
.
Millisecond
)
:
api
.
stop
()
wg
.
Done
()
}
}()
wg
.
Wait
()
if
len
(
api
.
logs
)
!=
0
{
t
.
Error
(
"expected logs to be empty"
)
}
if
len
(
api
.
messages
)
!=
0
{
t
.
Error
(
"expected messages to be empty"
)
}
}
rpc/util.go
View file @
982f73fa
...
@@ -20,10 +20,12 @@ import (
...
@@ -20,10 +20,12 @@ import (
"encoding/json"
"encoding/json"
"io"
"io"
"net/http"
"net/http"
"time"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/xeth"
)
)
var
rpclogger
=
logger
.
NewLogger
(
"RPC"
)
var
rpclogger
=
logger
.
NewLogger
(
"RPC"
)
...
@@ -100,3 +102,34 @@ func toLogs(logs state.Logs) (ls []Log) {
...
@@ -100,3 +102,34 @@ func toLogs(logs state.Logs) (ls []Log) {
return
return
}
}
type
whisperFilter
struct
{
messages
[]
xeth
.
WhisperMessage
timeout
time
.
Time
}
func
(
w
*
whisperFilter
)
add
(
msgs
...
xeth
.
WhisperMessage
)
{
w
.
messages
=
append
(
w
.
messages
,
msgs
...
)
}
func
(
w
*
whisperFilter
)
get
()
[]
xeth
.
WhisperMessage
{
w
.
timeout
=
time
.
Now
()
tmp
:=
w
.
messages
w
.
messages
=
nil
return
tmp
}
type
logFilter
struct
{
logs
state
.
Logs
timeout
time
.
Time
}
func
(
l
*
logFilter
)
add
(
logs
...
state
.
Log
)
{
l
.
logs
=
append
(
l
.
logs
,
logs
...
)
}
func
(
l
*
logFilter
)
get
()
state
.
Logs
{
l
.
timeout
=
time
.
Now
()
tmp
:=
l
.
logs
l
.
logs
=
nil
return
tmp
}
ui/qt/clipboard/capi.hpp
deleted
100644 → 0
View file @
00065853
#pragma once
#include "clipboard.hpp"
typedef
void
Clipboard_
;
Clipboard_
*
initClipboard
()
{
Clipboard
*
clipboard
=
new
(
Clipboard
);
return
static_cast
<
Clipboard_
*>
(
clipboard
);
}
ui/qt/clipboard/clipboard.cpp
deleted
100644 → 0
View file @
00065853
#include "clipboard.h"
#include <QClipboard>
Clipboard
::
Clipboard
()
{
connect
(
QApplication
::
clipboard
(),
&
QClipboard
::
dataChanged
,
[
this
]
{
emit
clipboardChanged
();});
}
QString
Clipboard
::
get
()
const
{
QClipboard
*
clipboard
=
QApplication
::
clipboard
();
return
clipboard
->
text
();
}
void
Clipboard
::
toClipboard
(
QString
_text
)
{
QClipboard
*
clipboard
=
QApplicationion
::
clipboard
();
clipboard
->
setText
(
_text
);
}
ui/qt/clipboard/clipboard.go
deleted
100644 → 0
View file @
00065853
package
clipboard
// #cgo CPPFLAGS: -I./
// #cgo CXXFLAGS: -std=c++0x -pedantic-errors -Wall -fno-strict-aliasing
// #cgo LDFLAGS: -lstdc++
// #cgo pkg-config: Qt5Quick
//
// #include "capi.hpp"
import
"C"
import
"github.com/obscuren/qml"
func
SetQMLClipboard
(
context
*
qml
.
Context
)
{
context
.
SetVar
(
"clipboard"
,
(
unsafe
.
Pointer
)(
C
.
initClipboard
()))
}
ui/qt/clipboard/clipboard.hpp
deleted
100644 → 0
View file @
00065853
#pragma once
#ifdef __cplusplus
extern
"C"
{
#endif
class
Clipboard
:
public
QObject
{
Q_OBJECT
Q_PROPERTY
(
QString
get
READ
get
WRITE
toClipboard
NOTIFY
clipboardChanged
)
public
:
Clipboard
();
virtual
~
Clipboard
(){}
Q_INVOKABLE
void
toClipboard
(
QString
_text
);
signals
:
void
clipboardChanged
();
};
#ifdef __cplusplus
}
// extern "C"
#endif
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