Skip to content
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

Integrate iam #30

Merged
merged 11 commits into from
Jan 30, 2024
12 changes: 6 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ type Downloader struct {

// VChanConfig vchan configuration.
type VChanConfig struct {
Domain int `json:"domain"`
XsRxPubPath string `json:"xsRxPubPath"`
XsTxPubPath string `json:"xsTxPubPath"`
XsRxPrivPath string `json:"xsRxPrivPath"`
XsTxPrivPath string `json:"xsTxPrivPath"`
CertStorage string `json:"certStorage"`
Domain int `json:"domain"`
XSOpenRXPath string `json:"xsOpenRxPath"`
XSOpenTXPath string `json:"xsOpenTxPath"`
XSSecureRXPath string `json:"xsSecureRxPath"`
XSSecureTXPath string `json:"xsSecureTxPath"`
CertStorage string `json:"certStorage"`
}

// IAMConfig IAM configuration.
Expand Down
24 changes: 12 additions & 12 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ func TestIAMConfig(t *testing.T) {
}

func TestGetVChanConfig(t *testing.T) {
if testCfg.VChan.XsRxPubPath != "xsPubPathRead" {
t.Errorf("Expected XSPath to be xsPubPathRead, got %s", testCfg.VChan.XsRxPubPath)
if testCfg.VChan.XSOpenRXPath != "xsOpenReadPath" {
t.Errorf("Expected XSPath to be xsOpenReadPath, got %s", testCfg.VChan.XSOpenRXPath)
}

if testCfg.VChan.XsTxPubPath != "xsPubPathWrite" {
t.Errorf("Expected XSPath to be xsPubPathWrite, got %s", testCfg.VChan.XsTxPubPath)
if testCfg.VChan.XSOpenTXPath != "xsOpenWritePath" {
t.Errorf("Expected XSPath to be xsOpenWritePath, got %s", testCfg.VChan.XSOpenTXPath)
}

if testCfg.VChan.XsRxPrivPath != "xsPrivPathRead" {
t.Errorf("Expected XSPath to be xsPrivPathRead, got %s", testCfg.VChan.XsRxPrivPath)
if testCfg.VChan.XSSecureRXPath != "xsSecureReadPath" {
t.Errorf("Expected XSPath to be xsSecureReadPath, got %s", testCfg.VChan.XSSecureRXPath)
}

if testCfg.VChan.XsTxPrivPath != "xsPrivPathWrite" {
t.Errorf("Expected XSPath to be xsPrivPathWrite, got %s", testCfg.VChan.XsTxPrivPath)
if testCfg.VChan.XSSecureTXPath != "xsSecureWritePath" {
t.Errorf("Expected XSPath to be xsSecureWritePath, got %s", testCfg.VChan.XSSecureTXPath)
}

if testCfg.VChan.Domain != 1 {
Expand Down Expand Up @@ -158,10 +158,10 @@ func createConfigFile(fileName string) (err error) {
"imageStoreDir": "/var/aos/storage",
"workingDir" : "workingDir",
"vchan": {
"xsRxPubPath": "xsPubPathRead",
"xsTxPubPath": "xsPubPathWrite",
"xsRxPrivPath": "xsPrivPathRead",
"xsTxPrivPath": "xsPrivPathWrite",
"xsOpenRxPath": "xsOpenReadPath",
"xsOpenTxPath": "xsOpenWritePath",
"xsSecureRxPath": "xsSecureReadPath",
"xsSecureTxPath": "xsSecureWritePath",
"domain": 1,
"certStorage": "certStorage"
},
Expand Down
26 changes: 14 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ func main() {
}
defer cryptoContext.Close()

iam, err := iamclient.New(config, cryptoContext, false)
iam, err := iamclient.New(config, cryptoContext, *provisioningMode)
if err != nil {
log.Errorf("Can't create iam client: %v", err)

return
}
defer iam.Close()

vchanPub := vchanmanager.NewVChan(config.VChan.XsRxPubPath, config.VChan.XsTxPubPath, config.VChan.Domain, nil)
defer vchanPub.Close()
vchanOpen := vchanmanager.NewVChan(config.VChan.XSOpenRXPath, config.VChan.XSOpenTXPath, config.VChan.Domain, nil)
defer vchanOpen.Close()

var mTLSConfig *tls.Config
if !*provisioningMode {
Expand All @@ -157,11 +157,11 @@ func main() {
}
}

vchanPriv := vchanmanager.NewVChan(
config.VChan.XsRxPrivPath, config.VChan.XsTxPrivPath, config.VChan.Domain, mTLSConfig)
defer vchanPriv.Close()
vchanSecure := vchanmanager.NewVChan(
config.VChan.XSSecureRXPath, config.VChan.XSSecureTXPath, config.VChan.Domain, mTLSConfig)
defer vchanSecure.Close()

vch, err := vchanmanager.New(downloadmanager, unpackmanager, vchanPub, vchanPriv)
vch, err := vchanmanager.New(downloadmanager, unpackmanager, vchanOpen, vchanSecure, *provisioningMode)
if err != nil {
log.Errorf("Can't create vchanmanager: %v", err)

Expand All @@ -177,13 +177,15 @@ func main() {
}
defer iamServer.Close()

cm, err := cmclient.New(config, iam, cryptoContext, vch, false)
if err != nil {
log.Errorf("Can't create cm client: %v", err)
if !*provisioningMode {
cm, err := cmclient.New(config, iam, cryptoContext, vch, false)
if err != nil {
log.Errorf("Can't create cm client: %v", err)

return
return
}
defer cm.Close()
}
defer cm.Close()

// Notify systemd
if _, err = daemon.SdNotify(false, daemon.SdNotifyReady); err != nil {
Expand Down
29 changes: 17 additions & 12 deletions vchanmanager/vchan.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"time"
"unsafe"

log "github.com/sirupsen/logrus"

"github.com/aoscloud/aos_common/aoserrors"
)

Expand Down Expand Up @@ -201,8 +203,10 @@ func (v *VChan) WriteMessage(msg Message) (err error) {
return err
}

if err = v.writeVchan(msg.Data); err != nil {
return err
if len(msg.Data) > 0 {
if err = v.writeVchan(msg.Data); err != nil {
return err
}
}

return nil
Expand Down Expand Up @@ -270,24 +274,25 @@ func (vc *connection) SetWriteDeadline(t time.Time) error {
func (v *VChan) newConnection() (conn *connection, err error) {
defer func() {
if err != nil {
v.Close()
conn.Close()
}
}()

vchanReader, err := v.initVchan(v.domain, v.xsRxPath)
log.WithFields(log.Fields{"rxPath": v.xsRxPath, "txPath": v.xsTxPath}).Debug("New connection")

conn = &connection{}

conn.vchanReader, err = v.initVchan(v.domain, v.xsRxPath)
if err != nil {
return nil, err
return conn, err
}

vchanWriter, err := v.initVchan(v.domain, v.xsTxPath)
conn.vchanWriter, err = v.initVchan(v.domain, v.xsTxPath)
if err != nil {
return nil, err
return conn, err
}

return &connection{
vchanReader: vchanReader,
vchanWriter: vchanWriter,
}, nil
return conn, nil
}

func (v *VChan) initVchan(domain int, xsPath string) (*C.struct_libxenvchan, error) {
Expand All @@ -297,7 +302,7 @@ func (v *VChan) initVchan(domain int, xsPath string) (*C.struct_libxenvchan, err
// To address Golang's inability to access bitfields in C structures,
// it is necessary to use server_init() instead of libxenvchan_server_init().

vchan, err := C.libxenvchan_server_init(nil, C.int(domain), cstr, 0, 0)
vchan, err := C.server_init(C.int(domain), cstr)
if vchan == nil {
return nil, aoserrors.Errorf("libxenvchan_server_init failed: %v", err)
}
Expand Down
Loading
Loading