mirror of https://github.com/namecoin/ncdns
Merge #103: Switch to rpcclient based on current upstream Conformal
2b1eed8
Switch to new rpcclient based on latest upstream Conformal (JeremyRand)
Pull request description:
Namecoin's fork of Conformal's RPC client library is ancient and unmaintained; switching to upstream eliminates a major source of potential bugs (and known bugs, e.g. the ConsensusJ and Electrum compatibility bugs that we had to patch).
Fixes https://github.com/namecoin/ncdns/issues/9
TODO:
- [ ] Wait for Conformal to merge https://github.com/btcsuite/btcd/pull/1457
- [ ] Wait for Conformal to merge https://github.com/btcsuite/btcd/pull/1460
- [x] Push `name_show` support for `ncjson` and `ncrpcclient`
- [x] Implement cookie authentication
- [x] Test cookie authentication
ACKs for commit 2b1eed:
Tree-SHA512: 157780613661af240d83a78d66386c66fcfeed0700088d263a20389c45b200db1b651ea985f345de2ac2f250bdafcc4cd5901579e9f5a97ddc13e77e7a7bcf39
pull/121/head
commit
4a1381cd41
@ -1,59 +0,0 @@
|
|||||||
package server
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func readCookieFile(path string) (username, password string, err error) {
|
|
||||||
b, err := ioutil.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s := strings.TrimSpace(string(b))
|
|
||||||
parts := strings.SplitN(s, ":", 2)
|
|
||||||
if len(parts) != 2 {
|
|
||||||
err = fmt.Errorf("malformed cookie file")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
username, password = parts[0], parts[1]
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func cookieRetriever(path string) func() (username, password string, err error) {
|
|
||||||
lastCheckTime := time.Time{}
|
|
||||||
lastModTime := time.Time{}
|
|
||||||
|
|
||||||
curUsername, curPassword := "", ""
|
|
||||||
var curError error
|
|
||||||
|
|
||||||
doUpdate := func() {
|
|
||||||
if !lastCheckTime.IsZero() && time.Now().Before(lastCheckTime.Add(30*time.Second)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
lastCheckTime = time.Now()
|
|
||||||
|
|
||||||
st, err := os.Stat(path)
|
|
||||||
if err != nil {
|
|
||||||
curError = err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
modTime := st.ModTime()
|
|
||||||
if !modTime.Equal(lastModTime) {
|
|
||||||
lastModTime = modTime
|
|
||||||
curUsername, curPassword, curError = readCookieFile(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return func() (username, password string, err error) {
|
|
||||||
doUpdate()
|
|
||||||
return curUsername, curPassword, curError
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue