-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
原有逻辑: lastore的通知都是dde-session-daemon去监听com.deepin.lastore.Job的状态,持续监听占用资源,而且交互不方便. 逻辑优化: lastore-daemon定义一套agent接口,由dde-daemon的lastore模块实现相关接口并导出,需要发通知和需要获取系统代理时,lastore-daemon调用agent接口完成. Log: lastore模块逻辑修改 Task: https://pms.uniontech.com/task-view-214983.html Influence: 通知和apt代理获取 Change-Id: I27df48576528a5932e7263f3945e156dda53dc3b
- Loading branch information
lichangze
committed
Dec 5, 2022
1 parent
a749e5a
commit 8e42a92
Showing
8 changed files
with
221 additions
and
929 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package lastore | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/godbus/dbus" | ||
lastore "github.com/linuxdeepin/go-dbus-factory/com.deepin.lastore" | ||
"github.com/linuxdeepin/go-lib/dbusutil" | ||
) | ||
|
||
// lastore agent的interface name | ||
const ( | ||
sessionAgentInterface = "com.deepin.lastore.Agent" | ||
) | ||
|
||
// 对应com.deepin.daemon.Network.GetProxy方法的key值 | ||
const ( | ||
proxyTypeHttp = "http" | ||
proxyTypeHttps = "https" | ||
proxyTypeFtp = "ftp" | ||
proxyTypeSocks = "socks" | ||
) | ||
|
||
// 对应系统代理环境变量 | ||
const ( | ||
envHttpProxy = "http_proxy" | ||
envHttpsProxy = "https_proxy" | ||
envFtpProxy = "ftp_proxy" | ||
envAllProxy = "all_proxy" | ||
) | ||
|
||
// Agent 需要实现GetManualProxy和SendNotify两个接口 | ||
type Agent struct { | ||
sysService *dbusutil.Service | ||
lastoreObj *Lastore | ||
sysLastore lastore.Lastore | ||
mu sync.Mutex | ||
} | ||
|
||
func newAgent(l *Lastore) (*Agent, error) { | ||
sysBus, err := dbusutil.NewSystemService() | ||
if err != nil { | ||
logger.Warning(err) | ||
return nil, err | ||
} | ||
a := &Agent{ | ||
sysService: sysBus, | ||
} | ||
a.lastoreObj = l | ||
a.sysLastore = lastore.NewLastore(a.sysService.Conn()) | ||
return a, nil | ||
} | ||
|
||
func (a *Agent) init() { | ||
err := a.sysService.Export("/com/deepin/lastore/agent", a) | ||
if err != nil { | ||
logger.Warning(err) | ||
return | ||
} | ||
err = a.sysLastore.Manager().RegisterAgent(0, "/com/deepin/lastore/agent") | ||
if err != nil { | ||
logger.Warning(err) | ||
} | ||
} | ||
|
||
func (a *Agent) destroy() { | ||
err := a.sysLastore.Manager().UnRegisterAgent(0, "/com/deepin/lastore/agent") | ||
if err != nil { | ||
logger.Warning(err) | ||
} | ||
} | ||
|
||
func (a *Agent) checkCallerAuth(sender dbus.Sender) bool { | ||
const rootUid = 0 | ||
uid, err := a.sysService.GetConnUID(string(sender)) | ||
if err != nil { | ||
return false | ||
} | ||
if uid != rootUid { | ||
logger.Warningf("not allow %v call this method", sender) | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
package lastore | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/godbus/dbus" | ||
"github.com/linuxdeepin/go-lib/dbusutil" | ||
) | ||
|
||
func (*Agent) GetInterfaceName() string { | ||
return sessionAgentInterface | ||
} | ||
|
||
func (a *Agent) GetManualProxy(sender dbus.Sender) (map[string]string, *dbus.Error) { | ||
// TODO 获取代理认证信息 | ||
if !a.checkCallerAuth(sender) { | ||
return nil, dbusutil.ToError(fmt.Errorf("not allow %v call this method", sender)) | ||
} | ||
method, err := a.lastoreObj.network.GetProxyMethod(0) | ||
if err != nil { | ||
logger.Warning(err) | ||
return nil, dbusutil.ToError(err) | ||
} | ||
if method != "manual" { | ||
return nil, dbusutil.ToError(errors.New("only support manual proxy")) | ||
} | ||
proxyTypeList := []string{ | ||
proxyTypeHttp, proxyTypeHttps, proxyTypeFtp, | ||
} | ||
proxyEnvMap := make(map[string]string) | ||
for _, typ := range proxyTypeList { | ||
host, port, err := a.lastoreObj.network.GetProxy(0, typ) | ||
if err != nil { | ||
logger.Warning(err) | ||
continue | ||
} | ||
proxyEnvMap[fmt.Sprintf("%s_proxy", typ)] = fmt.Sprintf("%s://%s:%s", proxyTypeHttp, host, port) | ||
} | ||
host, port, err := a.lastoreObj.network.GetProxy(0, proxyTypeSocks) | ||
if err != nil { | ||
logger.Warning(err) | ||
return proxyEnvMap, dbusutil.ToError(err) | ||
} | ||
proxyEnvMap[envAllProxy] = fmt.Sprintf("%s://%s:%s", proxyTypeSocks, host, port) | ||
return proxyEnvMap, nil | ||
} | ||
|
||
func (a *Agent) SendNotify(sender dbus.Sender, appName string, replacesId uint32, appIcon string, summary string, body string, actions []string, hints map[string]dbus.Variant, expireTimeout int32) (uint32, *dbus.Error) { | ||
if !a.checkCallerAuth(sender) { | ||
return 0, dbusutil.ToError(fmt.Errorf("not allow %v call this method", sender)) | ||
} | ||
logger.Info("receive notify from lastore daemon") | ||
id, err := a.lastoreObj.notifications.Notify(0, appName, replacesId, appIcon, summary, body, actions, hints, expireTimeout) | ||
return id, dbusutil.ToError(err) | ||
} | ||
|
||
func (a *Agent) CloseNotification(sender dbus.Sender, id uint32) *dbus.Error { | ||
if !a.checkCallerAuth(sender) { | ||
return dbusutil.ToError(fmt.Errorf("not allow %v call this method", sender)) | ||
} | ||
logger.Info("receive close notify from lastore daemon") | ||
return dbusutil.ToError(a.lastoreObj.notifications.CloseNotification(0, id)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.