feat: 本机默认信任自己且不能移除
This commit is contained in:
@@ -658,7 +658,11 @@ func (e *Engine) TrustAdd(id string) error {
|
||||
}
|
||||
|
||||
func (e *Engine) TrustRemove(id string) error {
|
||||
id = strings.TrimSpace(id)
|
||||
return e.st.Update(func(d *store.Data) error {
|
||||
if id != "" && id == d.EndpointID {
|
||||
return nil
|
||||
}
|
||||
out := d.Trust[:0]
|
||||
for _, it := range d.Trust {
|
||||
if it == id {
|
||||
@@ -790,6 +794,9 @@ func checkDelivery(opt Delivery, lim Limits, now time.Time) error {
|
||||
}
|
||||
|
||||
func trusted(d *store.Data, id string) bool {
|
||||
if id != "" && id == d.EndpointID {
|
||||
return true
|
||||
}
|
||||
for _, it := range d.Trust {
|
||||
if it == id {
|
||||
return true
|
||||
|
||||
@@ -202,6 +202,19 @@ func (d *Data) normalize() {
|
||||
if d.Results == nil {
|
||||
d.Results = []CmdResult{}
|
||||
}
|
||||
d.ensureSelf()
|
||||
}
|
||||
|
||||
func (d *Data) ensureSelf() {
|
||||
if d.EndpointID == "" {
|
||||
return
|
||||
}
|
||||
for _, it := range d.Trust {
|
||||
if it == d.EndpointID {
|
||||
return
|
||||
}
|
||||
}
|
||||
d.Trust = append([]string{d.EndpointID}, d.Trust...)
|
||||
}
|
||||
|
||||
func (s *Store) normalize() {
|
||||
|
||||
Reference in New Issue
Block a user