Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/ww/shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ww shell --with-exec

```
ww> (exec /ipfs/QmHash/bytecode.wasm :timeout 30s)
/protocol/identifier
abc123def
ww>
```

Expand Down
10 changes: 5 additions & 5 deletions cmd/ww/shell/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func (e Exec) Invoke(args ...core.Any) (core.Any, error) {
return nil, fmt.Errorf("failed to read bytecode: %w", err)
}

protocol, err := e.ExecBytes(ctx, bytecode)
procID, err := e.ExecBytes(ctx, bytecode)
if err != nil {
return nil, fmt.Errorf("failed to execute bytecode: %w", err)
}
return protocol, nil
return builtin.String(procID), nil

case files.Directory:
return nil, errors.New("TODO: directory support")
Expand All @@ -82,7 +82,7 @@ func (e Exec) Invoke(args ...core.Any) (core.Any, error) {
}
}

func (e Exec) ExecBytes(ctx context.Context, bytecode []byte) (protocol.ID, error) {
func (e Exec) ExecBytes(ctx context.Context, bytecode []byte) (string, error) {
f, release := e.Session.Exec().Exec(ctx, func(p system.Executor_exec_Params) error {
return p.SetBytecode(bytecode)
})
Expand All @@ -94,8 +94,8 @@ func (e Exec) ExecBytes(ctx context.Context, bytecode []byte) (protocol.ID, erro
return "", err
}

proto, err := result.Protocol()
return protocol.ID(proto), err
procID, err := result.Protocol()
return procID, err
}

func (e Exec) NewContext(opts map[builtin.Keyword]core.Any) (context.Context, context.CancelFunc) {
Expand Down
Binary file removed cmd/ww/shell/shell
Binary file not shown.
5 changes: 3 additions & 2 deletions system/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ type Proc struct {
Module api.Module
}

func (p *Proc) String() string {
return p.Endpoint.String()
// ID returns the process identifier (endpoint name) without the protocol prefix.
func (p *Proc) ID() string {
return p.Endpoint.Name
}

func (p *Proc) Close(ctx context.Context) error {
Expand Down
13 changes: 7 additions & 6 deletions system/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestProcConfig_New(t *testing.T) {

// Verify the endpoint has a valid name
assert.NotEmpty(t, proc.Endpoint.Name)
assert.Contains(t, proc.String(), "/ww/0.1.0/")
assert.NotEmpty(t, proc.ID())

// Clean up
proc.Close(ctx)
Expand Down Expand Up @@ -126,16 +126,16 @@ func TestProcConfig_New(t *testing.T) {
})
}

func TestProc_String(t *testing.T) {
func TestProc_ID(t *testing.T) {
endpoint := system.NewEndpoint()
proc := &system.Proc{
Endpoint: endpoint,
}

result := proc.String()
expected := endpoint.String()
result := proc.ID()
expected := endpoint.Name
assert.Equal(t, expected, result)
assert.Contains(t, result, "/ww/0.1.0/")
assert.NotEmpty(t, result)
}

func TestProc_Close(t *testing.T) {
Expand Down Expand Up @@ -429,6 +429,7 @@ func TestEndpoint_String(t *testing.T) {

assert.Equal(t, expected, result)
assert.Contains(t, result, "/ww/0.1.0/")
assert.Contains(t, result, endpoint.Name)
}

func TestEndpoint_Protocol(t *testing.T) {
Expand Down Expand Up @@ -521,7 +522,7 @@ func TestProc_Integration_WithRealWasm(t *testing.T) {
assert.NotNil(t, proc.Module, "Module should be initialized")
assert.NotNil(t, proc.Endpoint, "Endpoint should be initialized")
assert.NotEmpty(t, proc.Endpoint.Name, "Endpoint should have a name")
assert.Contains(t, proc.String(), "/ww/0.1.0/", "String should contain protocol prefix")
assert.NotEmpty(t, proc.ID(), "String should not be empty")

// Test that the poll function is exported
pollFunc := proc.Module.ExportedFunction("poll")
Expand Down
4 changes: 3 additions & 1 deletion system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (d DefaultExecutor) Exec(ctx context.Context, call Executor_exec) error {
}.New(ctx)
if err != nil {
return err
} else if err = res.SetProtocol(proc.String()); err != nil {
} else if err = res.SetProtocol(proc.ID()); err != nil {
defer proc.Close(ctx)
}

Expand Down Expand Up @@ -115,11 +115,13 @@ func NewEndpoint() *Endpoint {
}
}

// String returns the full protocol identifier including the /ww/0.1.0/ prefix.
func (e Endpoint) String() string {
proto := e.Protocol()
return string(proto)
}

// Protocol returns the libp2p protocol ID for this endpoint.
func (e Endpoint) Protocol() protocol.ID {
return protocol.ID("/ww/0.1.0/" + e.Name)
}
Expand Down
Loading