在Windows中如何能我油门上的应用程序域级别的带宽(在用户模式下)? [英] How can can I throttle bandwidth on an application domain level in Windows (in user mode)?

查看:211
本文介绍了在Windows中如何能我油门上的应用程序域级别的带宽(在用户模式下)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出以下发生:

    我的应用程序在Windows机器上运行
  • (称之为应用A)。
  • 我可以修改应用程序A的来源$ C ​​$ C引进带宽限制。
  • 我希望能够重用我的带宽限制code和拖放到任何其他应用程序,我有(换句话说,我想尝试和油门,以便在应用程序域级别的带宽不必再系数带宽限制现有的应用程序)。
  • 我想油门的累计上传和单独下载速度。举例来说,如果A有一个最大的5 Kbps的分配上传,那么所有的的上载流将封顶为5 Kbps的累计金额。
  • My application runs on a Windows machine (call it application A).
  • I can modify the source code of application A to introduce bandwidth throttling.
  • I would like to be able to reuse my bandwidth throttling code and drop it into any other applications that I have (in other words, I would like to try and throttle the bandwidth on an application domain level in order to not have to re-factor existing applications for bandwidth throttling).
  • I want to throttle A's cumulative upload and download speed separately. For example, if A has a maximum of 5 Kbps allotted to upload, then all of A's upload streams will be capped to a cumulative amount of 5 Kbps.

我的要求:

  • 在我不能用一个内核模式驱动程序。
  • 我需要添加限制在一个应用领域的水平。

我试图研究这个,尤其是对堆栈溢出,但找不到任何有用的东西我的情况:

I have tried to research into this, especially on Stack Overflow but could not find anything useful for my case:

  • 在我所看到的本例中使用ThrottledStream类包装的围绕一个Stream对象使用的时候,但我需要这是在域级别,将引进限制;采取这种方式是有问题的,因为它需要我重构了很多现有的code在其他应用程序。
  • 在我所看到的<一个href="http://stackoverflow.com/questions/2142906/using-c-c-is-it-possible-to-limit-network-traffic">this问题谁的答案谈到使用Windows过滤平台API。不幸的是,要求我的是,我绝对不能使用内核模式驱动程序来实现这一点,我的理解是,世界粮食计划署的API需要一个。
  • I have seen this example of using a ThrottledStream class wrapper around a Stream object that will introduce throttling when used, but I need this to be at a domain level; taking this approach is problematic because it would require me to refactor a lot of existing code in other applications.
  • I have seen this question who's answer speaks about using the Windows Filtering Platform API. Unfortunately, a requirement I have is that I absolutely can't use a kernel-mode driver to accomplish this, and my understanding is that the WFP API requires one.

有谁知道一个方法来实现,以节流应用程序在应用程序域级别我的具体带宽限制要求?

Does anyone know a way to implement my specific bandwidth throttling requirements in order to throttle applications on an application domain level?

推荐答案

我想我已经找到了解决办法。随着 QOS API ,您需要使用的 TcOpenInterface (你可以计算出通过调用的 TcEnumerateInterfaces )。随着你的界面处理,需要调用的 TcAddFlow 伴随着指针的 TC_GEN_FLOW 结构,它允许你同时指定 SendingFlowspec FLOWSPEC 结构)和 ReceivingFlowspec FLOWSPEC 结构),这包含 PeakBandwidth 成员。然后,让你的界面使用这个流程,你刚刚添加到它,你需要通过调用的 TcAddFilter ,如MSDN说的的TcAddFilter功能关联一个新的过滤器与现有的流程,允许数据包匹配过滤器被定向到相关联的流的。我认为要使其特定的应用程序,调用的 TcRegisterClient 可以做的伎俩,你将需要反正打电话,以获得客户端句柄从它的外观与TcEnumerateInterfaces和TcAddFlow使用(不过这仍有待检验)。我发现这个有用的例子以及(没有测试过)。

I think I have found a solution. With the QOS API, you need to get a handle to your target interface using TcOpenInterface (you can figure out which interface you want to target via a call to TcEnumerateInterfaces). With your interface handle, you need to call TcAddFlow along with a pointer to a TC_GEN_FLOW structure, which allows you to specify both a SendingFlowspec (FLOWSPEC structure) and a ReceivingFlowspec (FLOWSPEC structure) which contains a PeakBandwidth member. Then, to make your interface utilize this flow you've just added to it, you need to add a filter to your interface using a call to TcAddFilter, as MSDN says that the TcAddFilter function associates a new filter with an existing flow that allows packets matching the filter to be directed to the associated flow. I think that to make it application specific, calling TcRegisterClient may do the trick, which you will need to call anyways in order to get a client handle to use with TcEnumerateInterfaces and TcAddFlow from the looks of it (but this remains to be tested). I found this useful example as well (haven't tested it).

从MSDN服用, PeakBandwidth 成员的基于时间的发送许可对于给定的流量,以每秒字节数的上限。所述PeakBandwidth构件限制了可能已经从负担过重的网络资源与一次性或周期性数据突发,通过强制每秒数据传输天花板累积一个显著量的传输币,或令牌流。一些中间系统可利用这一信息优势,从而更有效地分配资源的。

Taken from MSDN, the PeakBandwidth member is the upper limit on time-based transmission permission for a given flow, in bytes per second. The PeakBandwidth member restricts flows that may have accrued a significant amount of transmission credits, or tokens from overburdening network resources with one-time or cyclical data bursts, by enforcing a per-second data transmission ceiling. Some intermediate systems can take advantage of this information, resulting in more efficient resource allocation.

这篇关于在Windows中如何能我油门上的应用程序域级别的带宽(在用户模式下)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆