-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5699 from multiversx/enable-http-server
[chain_simulator] Enable http server option
- Loading branch information
Showing
20 changed files
with
601 additions
and
130 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
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
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,21 @@ | ||
package api | ||
|
||
import "fmt" | ||
|
||
type fixedPortAPIConfigurator struct { | ||
restAPIInterface string | ||
mapShardPort map[uint32]int | ||
} | ||
|
||
// NewFixedPortAPIConfigurator will create a new instance of fixedPortAPIConfigurator | ||
func NewFixedPortAPIConfigurator(restAPIInterface string, mapShardPort map[uint32]int) *fixedPortAPIConfigurator { | ||
return &fixedPortAPIConfigurator{ | ||
restAPIInterface: restAPIInterface, | ||
mapShardPort: mapShardPort, | ||
} | ||
} | ||
|
||
// RestApiInterface will return the api interface for the provided shard | ||
func (f *fixedPortAPIConfigurator) RestApiInterface(shardID uint32) string { | ||
return fmt.Sprintf("%s:%d", f.restAPIInterface, f.mapShardPort[shardID]) | ||
} |
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,37 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
type freePortAPIConfigurator struct { | ||
restAPIInterface string | ||
} | ||
|
||
// NewFreePortAPIConfigurator will create a new instance of freePortAPIConfigurator | ||
func NewFreePortAPIConfigurator(restAPIInterface string) *freePortAPIConfigurator { | ||
return &freePortAPIConfigurator{ | ||
restAPIInterface: restAPIInterface, | ||
} | ||
} | ||
|
||
// RestApiInterface will return the rest api interface with a free port | ||
func (f *freePortAPIConfigurator) RestApiInterface(_ uint32) string { | ||
return fmt.Sprintf("%s:%d", f.restAPIInterface, getFreePort()) | ||
} | ||
|
||
func getFreePort() int { | ||
// Listen on port 0 to get a free port | ||
l, err := net.Listen("tcp", "localhost:0") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer func() { | ||
_ = l.Close() | ||
}() | ||
|
||
// Get the port number that was assigned | ||
addr := l.Addr().(*net.TCPAddr) | ||
return addr.Port | ||
} |
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,15 @@ | ||
package api | ||
|
||
import "github.com/multiversx/mx-chain-go/facade" | ||
|
||
type noAPIInterface struct{} | ||
|
||
// NewNoApiInterface will create a new instance of noAPIInterface | ||
func NewNoApiInterface() *noAPIInterface { | ||
return new(noAPIInterface) | ||
} | ||
|
||
// RestApiInterface will return the value for disable api interface | ||
func (n noAPIInterface) RestApiInterface(_ uint32) string { | ||
return facade.DefaultRestPortOff | ||
} |
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
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
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
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
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
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
Oops, something went wrong.