-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client: Update server host #1605
Conversation
24c6f8a
to
301a141
Compare
client/core/account.go
Outdated
atomic.StoreUint32(&newDc.reportingConnects, 1) | ||
c.wg.Add(1) | ||
go c.listen(newDc) | ||
go newDc.subPriceFeed() | ||
|
||
c.connMtx.Lock() | ||
c.conns[newDc.acct.host] = newDc | ||
c.connMtx.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section is a duplicate. Maybe a new upgradeConnection
method?
client/core/account_test.go
Outdated
newHost string | ||
feePending bool | ||
expectError bool | ||
newPubKey *secp256k1.PublicKey |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you don't need the newPubKey
and newHost
fields. They are always the same. Just use var
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newPubKey
isn't always the same, but you're right about newHost
.
client/webserver/api.go
Outdated
@@ -418,6 +418,31 @@ func (s *WebServer) apiUpdateCert(w http.ResponseWriter, r *http.Request) { | |||
writeJSON(w, simpleAck(), s.indent) | |||
} | |||
|
|||
func (s *WebServer) apiUpdateDexHost(w http.ResponseWriter, r *http.Request) { | |||
form := new(updateHostForm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If updateHostForm
is only used once here, how about an anonymous struct
.
form := new(struct {
Pass encode.PassBytes `json:"pw"`
OldHost string `json:"oldHost"`
NewHost string `json:"newHost"`
Cert string `json:"cert"`
})
I think it improves readability.
client/core/account.go
Outdated
// UpdateDexHost updates the host for a connection to a dex. The dex at oldHost | ||
// and newHost must be the same dex, which means that the dex at both hosts use | ||
// the same public key. | ||
func (c *Core) UpdateDexHost(oldHost, newHost string, appPW []byte, certI interface{}) (*Exchange, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting the difference of the capitalization of DEX
between UpdateDexHost
with GetDEXConfig
.
if (this.knownExchanges.length === 0) { | ||
Doc.show(page.customBox) | ||
Doc.hide(page.showCustom, page.knownXCs, page.pickServerMsg, page.addCustomMsg) | ||
} else { | ||
Doc.hide(page.customBox) | ||
Doc.show(page.showCustom) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that, I think it must be because I forgot to update the cache buster. I've updated it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still happening for me.
I see the problem. It's a pre-existing bug. The button won't be displayed when the password is cached, since we're hiding page.auth
, which includes the submit button.
During the initial registration sequence, it doesn't matter, because we
Doc.bind(page.showCustom, 'click', () => {
Doc.hide(page.showCustom)
Doc.show(page.customBox, page.auth)
})
But when the custom form is displayed by default (because we already registered at the only DEX), we never hit that code.
I think the easiest solution is to
if (this.knownExchanges.length === 0) Doc.show(page.auth)
if (this.knownExchanges.length === 0) { | ||
Doc.show(page.customBox) | ||
Doc.hide(page.showCustom, page.knownXCs, page.pickServerMsg, page.addCustomMsg) | ||
} else { | ||
Doc.hide(page.customBox) | ||
Doc.show(page.showCustom) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still happening for me.
I see the problem. It's a pre-existing bug. The button won't be displayed when the password is cached, since we're hiding page.auth
, which includes the submit button.
During the initial registration sequence, it doesn't matter, because we
Doc.bind(page.showCustom, 'click', () => {
Doc.hide(page.showCustom)
Doc.show(page.customBox, page.auth)
})
But when the custom form is displayed by default (because we already registered at the only DEX), we never hit that code.
I think the easiest solution is to
if (this.knownExchanges.length === 0) Doc.show(page.auth)
@buck54321 I see it now. I need to make a habit of testing with the password both cached and not cached. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing well for me.
client/webserver/site/src/localized_html/en-US/bodybuilder.tmpl
Outdated
Show resolved
Hide resolved
client/core/account.go
Outdated
err = c.AccountDisable(appPW, oldHost) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to disable old account: %w", err) | ||
} | ||
|
||
_, err = c.discoverAccount(newDc, crypter) | ||
if err != nil { | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if the order of these AccountDisable
and discoverAccount
should be switched.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it so that it disconnects the dex first, then does discoverAccount
, then finally removes the old dex from the db.
client/webserver/http.go
Outdated
// KnownUnregisteredExchanges returns all the known exchanges that | ||
// the user has not registered for. | ||
func (s *WebServer) KnownUnregisteredExchanges(registeredExchanges map[string]*core.Exchange) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to export.
if (this.pwCache) this.pwCache.pw = pw | ||
this.success(res.xc, cert) | ||
} | ||
|
||
makeDexUpdater (dexToUpdate: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please comment here that this is a one way function. The changes made during makeDexUpdater
are not reversed upon refresh
. So the same DEXAddressForm
can't do double duty for new registration and host name updates.
I would actually prefer that makeDexUpdater
was used internally based on an argument to the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove makeDexUpdater
now? I believe you have it done in if (dexToUpdate) {
now.
@@ -22,6 +22,9 @@ | |||
<button id="updateCertBtn" class="bg2 selected">[[[Update TLS Certificate]]]</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not from this PR, but from #1602 (comment), I think only part of solution made it into the final product.
Can you get rid of the <h4>
up above and do something like
<div class="flex-center fs16 mb-2">
<span class="me-2 connection ico-connection d-hide" id="connectedIcon"></span>
<span class="me-2 disconnected ico-disconnected d-hide" id="disconnectedIcon"></span>
<span id="connectionStatus"></span>
</div>
client/core/account.go
Outdated
oldHost, newHost) | ||
} | ||
|
||
err = c.AccountDisable(appPW, oldHost) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are active orders, we'll fail here, but should we check that condition higher up to prevent making an unnecessary connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few little things left, but seems g2g.
if (this.pwCache) this.pwCache.pw = pw | ||
this.success(res.xc, cert) | ||
} | ||
|
||
makeDexUpdater (dexToUpdate: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove makeDexUpdater
now? I believe you have it done in if (dexToUpdate) {
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Working very well.
Might as well rebase while waiting for @buck54321 to circle back since your merge base is quite old. I tested a rebased branch though.
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a weird place to end up, but I think the likelihood of getting here is virtually nil.
DEX servers are able to advertise on multiple host names. This update gives users of the dex client the ability to switch between the different host names of the same dex. - client/core: Add `UpdateDexHost` method which takes a current dex host and a new host name, and if the dex at both host names use the same dex pub key, the host name is updated. Also, adding a dex with the same pub key as a dex which is already registered is now blocked. - ui: Adds a button on the dex settings page to allow updating the dex host. The DEXAddressForm is reused for this purpose. The DEXAddressPopup is also updated to not show known exchanges that the user is already registered for.
DEX servers are able to advertise on multiple host names. This update gives users of the dex client the ability to switch between the different host names of the same dex.
client/core: Add
UpdateDexHost
method which takesa current dex host and a new host name, and if the dex
at both host names use the same dex pub key, the host
name is updated. Also, adding a dex with the same pub
key as a dex which is already registered is now blocked.
ui: Adds a button on the dex settings page to allow updating
the dex host. The DEXAddressForm is reused for this purpose.
The DEXAddressPopup is also updated to not show known
exchanges that the user is already registered for.