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

Small changes #51

Merged
merged 1 commit into from
Sep 15, 2023
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
1 change: 1 addition & 0 deletions config/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type baseOptions struct {
AddressChangeThreshold int `yaml:"AddressChangeThreshold"`
OriginatorShuffleProbability float32 `yaml:"OriginatorShuffleProbability"`
NonOriginatorShuffleProbability float32 `yaml:"NonOriginatorShuffleProbability"`
ShufflingPeriod int `yaml:"ShufflingPeriod"`
AddressRange int
StorageDepth int
}
Expand Down
1 change: 1 addition & 0 deletions config/default_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func getDefaultConfig() Config {
AddressChangeThreshold: 0, // non-positive means no limit
OriginatorShuffleProbability: 0.0, // 0.0
NonOriginatorShuffleProbability: 0.0, // 0.0
ShufflingPeriod: 0, // 0
ReplicationFactor: 4,
AdjustableThresholdExponent: 3,
OutputOptions: outputOptions{
Expand Down
4 changes: 4 additions & 0 deletions config/get_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func GetNonOriginatorShuffleProbability() float32 {
return theconfig.BaseOptions.NonOriginatorShuffleProbability
}

func GetShufflingPeriod() int {
return theconfig.BaseOptions.ShufflingPeriod
}

func IsForgivenessEnabled() bool {
return theconfig.ExperimentOptions.ForgivenessEnabled
}
Expand Down
1 change: 1 addition & 0 deletions model/parts/types/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (network *Network) node(nodeId NodeId) *Node {
RerouteMutex: &sync.Mutex{},
},
AdjLock: sync.RWMutex{},
CreationEpoch: 0,
}
if len(network.NodesMap) == 0 {
network.NodesMap = make(map[NodeId]*Node)
Expand Down
1 change: 1 addition & 0 deletions model/parts/types/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Node struct {
PendingStruct PendingStruct
RerouteStruct RerouteStruct
AdjLock sync.RWMutex
CreationEpoch int
}

// Adds a one-way connection from node to other
Expand Down
4 changes: 3 additions & 1 deletion model/parts/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ func (s *State) GetOriginatorId(originatorIndex int) NodeId {
if node == nil {
panic("Node not found")
}
if node.OriginatorStruct.RequestCount > config.GetAddressChangeThreshold() {
if node.CreationEpoch + config.GetShufflingPeriod() <= s.Epoch {

newNode, err := s.Graph.NewNode()
if err != nil {
panic(err)
}
// The new node is not going to get requests
newNode.Deactivate()
newNode.CreationEpoch = s.Epoch
s.Originators[originatorIndex] = newNode.Id
}
}
Expand Down
18 changes: 8 additions & 10 deletions model/parts/update/update_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,26 @@ func Graph(state *types.State, requestResult types.RequestResult, curTimeStep in
edgeData1 := state.Graph.GetEdgeData(payment.FirstNodeId, payment.PayNextId)
edgeData2 := state.Graph.GetEdgeData(payment.PayNextId, payment.FirstNodeId)
price := utils.PeerPriceChunk(payment.PayNextId, payment.ChunkId)
actualPrice := edgeData1.A2B - edgeData2.A2B + price
if config.IsPayOnlyForCurrentRequest() {
actualPrice = price
}
actualPrice := price
if actualPrice < 0 {
continue
} else {
if !config.IsPayOnlyForCurrentRequest() {
actualPrice = edgeData1.A2B - edgeData2.A2B + price
newEdgeData1 := edgeData1
newEdgeData1.A2B = 0
state.Graph.SetEdgeData(payment.FirstNodeId, payment.PayNextId, newEdgeData1)

newEdgeData2 := edgeData2
newEdgeData2.A2B = 0
state.Graph.SetEdgeData(payment.PayNextId, payment.FirstNodeId, newEdgeData2)
} else {
// Important fix: Reduce debt here, since it debt will be added again below.
// Idea is, paying for the current request should not effect the edge balance.
newEdgeData1 := edgeData1
newEdgeData1.A2B = edgeData1.A2B - price
state.Graph.SetEdgeData(payment.FirstNodeId, payment.PayNextId, newEdgeData1)
}
// Important fix: Reduce debt here, since it debt will be added again below.
// Idea is, paying for the current request with or without the rest of debt
// should not effect the edge balance.
newEdgeData1 := edgeData1
newEdgeData1.A2B = edgeData1.A2B - price
state.Graph.SetEdgeData(payment.FirstNodeId, payment.PayNextId, newEdgeData1)
}
// fmt.Println("Payment from ", payment.FirstNodeId, " to ", payment.PayNextId, " for chunk ", payment.ChunkId, " with price ", actualPrice)
paymentWithPrice = types.PaymentWithPrice{Payment: payment, Price: actualPrice}
Expand Down
7 changes: 7 additions & 0 deletions model/parts/update/update_neighbors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import (
)

func Neighbors(globalState *types.State) bool {
if config.GetShufflingPeriod() <= 0 {
return true
}
if globalState.Epoch%config.GetShufflingPeriod() != 0 {
return true
}

// Update neighbors with probability p
if config.GetOriginatorShuffleProbability() <= 0 && config.GetNonOriginatorShuffleProbability() <= 0 {
return true
Expand Down