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

Optimize network usage #802

Merged
merged 7 commits into from
Sep 23, 2021
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: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ func applyProfile(ctx *cli.Context, cfg *Config) {
default:
println("unknown node profile")
}
} else {
applyDefaultProfile(cfg)
}
if cfg.IpfsConf.GracePeriod == "" {
cfg.IpfsConf.GracePeriod = "40s"
Expand Down
3 changes: 2 additions & 1 deletion ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (p *ipfsProxy) AddFile(absPath string, data io.ReadCloser, fi os.FileInfo)

file, _ := files.NewReaderPathFile(absPath, data, fi)
defer file.Close()
path, err := api.Unixfs().Add(ctx, file, options.Unixfs.Nocopy(true), options.Unixfs.CidVersion(1))
path, err := api.Unixfs().Add(ctx, file, options.Unixfs.Pin(true), options.Unixfs.Nocopy(true), options.Unixfs.CidVersion(1))
select {
case <-ctx.Done():
err = errors.New("timeout while writing data to ipfs from reader")
Expand Down Expand Up @@ -633,6 +633,7 @@ func configureIpfs(cfg *config.IpfsConfig) (*ipfsConf.Config, error) {
ipfsConfig.Swarm.ConnMgr.LowWater = cfg.LowWater
ipfsConfig.Swarm.ConnMgr.HighWater = cfg.HighWater
ipfsConfig.Reprovider.Interval = cfg.ReproviderInterval
ipfsConfig.Reprovider.Strategy = "pinned"
ipfsConfig.Swarm.Transports.Security.Noise = ipfsConf.Disabled

ipfsConfig.Swarm.EnableRelayHop = false
Expand Down
9 changes: 3 additions & 6 deletions protocol/peerSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,14 @@ func (ps *peerSet) SendWithFilter(msgcode uint64, key string, payload interface{
ps.SendWithFilterAndExpiration(msgcode, key, payload, shardId, highPriority, msgCacheAliveTime)
}

func (ps *peerSet) shouldSendToPeer(p *protoPeer, msgShardId common.ShardId, highPriority bool) bool {
peersCnt := ps.Len()
func (ps *peerSet) shouldSendToPeer(p *protoPeer, msgShardId common.ShardId, peersCnt int, highPriority bool) bool {
if msgShardId == common.MultiShard || p.shardId == msgShardId || p.shardId == common.MultiShard || peersCnt < 4 || highPriority {
return true
}
rnd := rand.Float32()
return rnd > 1-1.8/float32(peersCnt)
}



func (ps *peerSet) SendWithFilterAndExpiration(msgcode uint64, key string, payload interface{}, msgShardId common.ShardId, highPriority bool, expiration time.Duration) {
peers := ps.Peers()

Expand All @@ -130,7 +127,7 @@ func (ps *peerSet) SendWithFilterAndExpiration(msgcode uint64, key string, paylo
}

for _, p := range peers {
if ps.shouldSendToPeer(p, msgShardId, highPriority) {
if ps.shouldSendToPeer(p, msgShardId, len(peers), highPriority) {
if _, ok := p.msgCache.Get(key); !ok {
p.markKeyWithExpiration(key, expiration)
p.sendMsg(msgcode, payload, msgShardId, highPriority)
Expand All @@ -142,7 +139,7 @@ func (ps *peerSet) SendWithFilterAndExpiration(msgcode uint64, key string, paylo
func (ps *peerSet) Send(msgcode uint64, payload interface{}, msgShardId common.ShardId) {
peers := ps.Peers()
for _, p := range peers {
if ps.shouldSendToPeer(p, msgShardId, false) {
if ps.shouldSendToPeer(p, msgShardId, len(peers), false) {
p.sendMsg(msgcode, payload, msgShardId, false)
}
}
Expand Down