Allow websocket connections from all origins

ethereum
Martin Boehm 2018-12-11 12:14:05 +01:00
parent 4b39519750
commit d01081fd83
3 changed files with 13 additions and 7 deletions

View File

@ -505,10 +505,10 @@ func onNewTxAddr(tx *bchain.Tx, desc bchain.AddressDescriptor, isOutput bool) {
}
func pushSynchronizationHandler(nt bchain.NotificationType) {
glog.V(1).Info("MQ: notification ", nt)
if atomic.LoadInt32(&inShutdown) != 0 {
return
}
glog.V(1).Info("MQ: notification ", nt)
if nt == bchain.NotificationNewBlock {
chanSyncIndex <- struct{}{}
} else if nt == bchain.NotificationNewTx {

View File

@ -76,6 +76,7 @@ func NewWebsocketServer(db *db.RocksDB, chain bchain.BlockChain, txCache *db.TxC
upgrader: &websocket.Upgrader{
ReadBufferSize: 1024 * 32,
WriteBufferSize: 1024 * 32,
CheckOrigin: checkOrigin,
},
db: db,
txCache: txCache,
@ -90,6 +91,11 @@ func NewWebsocketServer(db *db.RocksDB, chain bchain.BlockChain, txCache *db.TxC
return s, nil
}
// allow all origins, at least for now
func checkOrigin(r *http.Request) bool {
return true
}
// ServeHTTP sets up handler of websocket channel
func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {

View File

@ -136,9 +136,9 @@
}
subscribeNewBlockId = subscribe(method, params, function (result) {
document.getElementById('subscribeNewBlockResult').innerText += JSON.stringify(result).replace(/,/g, ", ") + "\n";
document.getElementById('subscribeNewBlockId').innerText = subscribeNewBlockId;
document.getElementById('unsubscribeNewBlockButton').setAttribute("style", "display: inherit;");
});
document.getElementById('subscribeNewBlockId').innerText = subscribeNewBlockId;
document.getElementById('unsubscribeNewBlockButton').setAttribute("style", "display: inherit;");
}
function unsubscribeNewBlock() {
@ -166,9 +166,9 @@
}
subscribeAddressesId = subscribe(method, params, function (result) {
document.getElementById('subscribeAddressesResult').innerText += JSON.stringify(result).replace(/,/g, ", ") + "\n";
document.getElementById('subscribeAddressesIds').innerText = subscribeAddressesId;
document.getElementById('unsubscribeAddressesButton').setAttribute("style", "display: inherit;");
});
document.getElementById('subscribeAddressesIds').innerText = subscribeAddressesId;
document.getElementById('unsubscribeAddressesButton').setAttribute("style", "display: inherit;");
}
function unsubscribeAddresses() {
@ -347,9 +347,9 @@
<span id="subscribeAddressesIds"></span>
</div>
<div class="col">
<input class="btn btn-secondary" id="unsubscribeAddressesButton" style="display: none;" type="button" value="unsubscribe" onclick="unsubscribeAddresses()">
</div>
<input class="btn btn-secondary" id="unsubscribeAddressesButton" style="display: none;" type="button" value="unsubscribe" onclick="unsubscribeAddresses()">
</div>
</div>
<div class="row">
<div class="col" id="subscribeAddressesResult"></div>
</div>